create a structure from a matrix
显示 更早的评论
I have an nx2 matrix. The second column is meant to provide indexes into the first column: ex. please ignore the given x, it is there so the matrix below would look like I wanted it too.
x=[1;0.5]
0.5 1
0.75 1
1.0 1
1.25 1
0.2 2
0.4 2
0.6 2
0.15 3
0.3 3
0.45 3
I am trying to create a for loop to create a structure where each of the values in column 1 are put into its own structure based on the value in column 2. What I have so far:
trialdata=load(file);
numb=trialdata(:,2);
cell.numb=num2cell(MUnumb);
DTs=trialdata(:,1);
cell.DTs=num2cell(DTs);
DTs_per_numb=struct(field,trialdata);
fields='number';
for i={1:max(numb)};
DTs_per_numb.(fields{i})=cell.DTs(cell.numb==i);
end
I am getting the following error:
Cell contents reference from a non-cell array object.
Then need to iterate through each part of structure to run stats (ex. mean) Would appreciate any help. Thanks
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!