在MATLAB

时间:2016-05-11 13:38:45

标签: arrays matlab nested structure

我有一个嵌套的结构数组,我想重新排列成一个大的单元格数组。结构如下:

  • 第1级:
    EpochedAll 1x1 strucutre
  • 第二级:主题
    epoched02 1x1 strucutre
    epoched03 1x1 strucutre
    ... 1x1结构
    epoched12 1x1 strucutre
  • 第3级:肌肉
    ECR 1x1结构 FCR 1x1结构

  • 第4级条件
    绿色124x2双倍(每个主题和条件的试验次数不同)
    红色122x2双
    控制105x2双重

我想要的是一个包含以下列的单元格数组:
来自条件的价值...主体的身份...肌肉的身份...身体的身份




我是MATLAB的新手和一般编程人员,非常感谢从哪里开始的任何指针或想法

1 个答案:

答案 0 :(得分:0)

所以这会根据肌肉重新排列数据:

names = fieldnames(epochedAll); 
mus = {'ECR','FCR'};
cond = {'green', 'red','control'};
masterArray = []

%This program will loop through each subject and the conditions of a given
%muscle (the muscle is chosen by writing either ECR or FCR in the ecrarray
%variable below. It will then concatenate all of the data from each condition of
%each patient into one master array, with numbers representing the subject
%and condition, along with the condition values.

for x = 1:length(names) 
    for z = 1: length(cond) 
        tempArray = []   
        ecrarray = epochedAll.(names{x}).ECR.(cond{z})(:,1);
        tempArray = vertcat(tempArray, ecrarray); 
        len = length(tempArray);
        column = zeros(len, 1);
        column(column == 0) = z;
        condCol = column;
        column(column == z) = x; 
        subjCol = column;
        tempArray = horzcat(tempArray, condCol, subjCol); 
        masterArray = vertcat(masterArray, tempArray);

    end
end

希望这可以解雇别人