将多个值放入 1 个单元格(例如数组{1} = [1,2,3])以进行多条件 SPM 分析;我得到的只是数组{1} = [1] [2] [3]
Put several values into 1 cell (e.g. array{1} = [1,2,3]) for multiple condition SPM analysis; All I get is array{1} = [1] [2] [3]
我正在努力完成一些 fMRI 数据的一级分析,因为这是我第一次以这种方式使用 SPM,我的挫败感似乎没有尽头。 SPM 包括以下具体说明:
"This *.mat file must include the following cell arrays (each 1 x n): names, onsets, and durations. eg. names=cell(1,5), onsets=cell(1,5), durations=cell(1,5), then names{2}="第二个条件",开始{2}=[3,5,19,22],持续时间{2}=[0,0,0 ,0], 包含第二个条件所需的详细信息。"
我正在使用的代码从存储行为数据的各种 excel 文件中获取我需要的数据,并将它们添加到这些元胞数组中。
sessionFiles = dir('*.xlsx');
allNames = {sessionFiles.name}';
conditions = 36;
% go through excel files to grab relevant column information for SPM
for i=1:length(sessionFiles)
[~,fileName,~] = fileparts(allNames{i});
% initialize cells SPM needs
names = cell(1,conditions);
onsets = cell(1,conditions);
durations = {1.75};
durations = repmat(durations,1,conditions);
% read in excel file
[num,~,~] = xlsread(sessionFiles(i).name);
trialType = num(:,6);
% grab condition information from columns: seconds=9, name=6
for j=1:conditions
index = find(trialType==j);
trialOnsets = cell(1,length(index));
names{1,j} = j;
for k=1:length(index)
trialOnsets{1,k}=double(num(index(k),9));
end
onsets{1,j} = trialOnsets;
end
% save new data for SPM
save(fileName,'names','onsets','durations');
clear names onsets durations fileName num raw text
end
我找到了一个显示每个单元格应如下所示的示例:
我只是不知道如何自动抓取数字并将它们放入这样的单元格中。
我知道这不是 SPM 论坛,但我看到了一些问题,我想试试我的运气。
在行 trialOnsets = cell(1,length(index));
中,trialOnsets
被指定为大小为 1xlength(index)
的元胞数组。然后,trialOnsets
被分配给 onsets{1,j}
。使用此工作流程,onsets
的每个单元格的大小将为 1xlength(index)
.
相反,onsets
的每个单元格的大小应为 1x1
,而 onsets
中的每个 1x1 单元格的大小应为 1xlength(index)
的矩阵。为此,请执行以下操作。
- 将
trialOnsets
指定为矩阵,而不是元胞数组。为此,请将 trialOnsets = cell(1,length(index));
替换为 trialOnsets = zeros(1,length(index));
。
- 将
num
中的值分配给 trialOnsets
,它现在是一个矩阵(以前是一个元胞数组)。为此,请将 trialOnsets{1,k}=double(num(index(k),9));
替换为 trialOnsets(1,k)=double(num(index(k),9));
。
编辑后的代码应该如下:
sessionFiles = dir('*.xlsx');
allNames = {sessionFiles.name}';
conditions = 36;
% go through excel files to grab relevant column information for SPM
for i=1:length(sessionFiles)
[~,fileName,~] = fileparts(allNames{i});
% initialize cells SPM needs
names = cell(1,conditions);
onsets = cell(1,conditions);
durations = {1.75};
durations = repmat(durations,1,conditions);
% read in excel file
[num,~,~] = xlsread(sessionFiles(i).name);
trialType = num(:,6);
% grab condition information from columns: seconds=9, name=6
for j=1:conditions
index = find(trialType==j);
trialOnsets = zeros(1,length(index));
names{1,j} = j;
for k=1:length(index)
trialOnsets(1,k)=double(num(index(k),9));
end
onsets{1,j} = trialOnsets;
end
% save new data for SPM
save(fileName,'names','onsets','durations');
clear names onsets durations fileName num raw text
end
我无法测试这段代码,因为没有样本数据。让我知道这是否适合你。
我正在努力完成一些 fMRI 数据的一级分析,因为这是我第一次以这种方式使用 SPM,我的挫败感似乎没有尽头。 SPM 包括以下具体说明:
"This *.mat file must include the following cell arrays (each 1 x n): names, onsets, and durations. eg. names=cell(1,5), onsets=cell(1,5), durations=cell(1,5), then names{2}="第二个条件",开始{2}=[3,5,19,22],持续时间{2}=[0,0,0 ,0], 包含第二个条件所需的详细信息。"
我正在使用的代码从存储行为数据的各种 excel 文件中获取我需要的数据,并将它们添加到这些元胞数组中。
sessionFiles = dir('*.xlsx');
allNames = {sessionFiles.name}';
conditions = 36;
% go through excel files to grab relevant column information for SPM
for i=1:length(sessionFiles)
[~,fileName,~] = fileparts(allNames{i});
% initialize cells SPM needs
names = cell(1,conditions);
onsets = cell(1,conditions);
durations = {1.75};
durations = repmat(durations,1,conditions);
% read in excel file
[num,~,~] = xlsread(sessionFiles(i).name);
trialType = num(:,6);
% grab condition information from columns: seconds=9, name=6
for j=1:conditions
index = find(trialType==j);
trialOnsets = cell(1,length(index));
names{1,j} = j;
for k=1:length(index)
trialOnsets{1,k}=double(num(index(k),9));
end
onsets{1,j} = trialOnsets;
end
% save new data for SPM
save(fileName,'names','onsets','durations');
clear names onsets durations fileName num raw text
end
我找到了一个显示每个单元格应如下所示的示例:
我只是不知道如何自动抓取数字并将它们放入这样的单元格中。
我知道这不是 SPM 论坛,但我看到了一些问题,我想试试我的运气。
在行 trialOnsets = cell(1,length(index));
中,trialOnsets
被指定为大小为 1xlength(index)
的元胞数组。然后,trialOnsets
被分配给 onsets{1,j}
。使用此工作流程,onsets
的每个单元格的大小将为 1xlength(index)
.
相反,onsets
的每个单元格的大小应为 1x1
,而 onsets
中的每个 1x1 单元格的大小应为 1xlength(index)
的矩阵。为此,请执行以下操作。
- 将
trialOnsets
指定为矩阵,而不是元胞数组。为此,请将trialOnsets = cell(1,length(index));
替换为trialOnsets = zeros(1,length(index));
。 - 将
num
中的值分配给trialOnsets
,它现在是一个矩阵(以前是一个元胞数组)。为此,请将trialOnsets{1,k}=double(num(index(k),9));
替换为trialOnsets(1,k)=double(num(index(k),9));
。
编辑后的代码应该如下:
sessionFiles = dir('*.xlsx');
allNames = {sessionFiles.name}';
conditions = 36;
% go through excel files to grab relevant column information for SPM
for i=1:length(sessionFiles)
[~,fileName,~] = fileparts(allNames{i});
% initialize cells SPM needs
names = cell(1,conditions);
onsets = cell(1,conditions);
durations = {1.75};
durations = repmat(durations,1,conditions);
% read in excel file
[num,~,~] = xlsread(sessionFiles(i).name);
trialType = num(:,6);
% grab condition information from columns: seconds=9, name=6
for j=1:conditions
index = find(trialType==j);
trialOnsets = zeros(1,length(index));
names{1,j} = j;
for k=1:length(index)
trialOnsets(1,k)=double(num(index(k),9));
end
onsets{1,j} = trialOnsets;
end
% save new data for SPM
save(fileName,'names','onsets','durations');
clear names onsets durations fileName num raw text
end
我无法测试这段代码,因为没有样本数据。让我知道这是否适合你。