Structure to matrix

3 次查看(过去 30 天)
Anna
Anna 2012-4-24
Hello,
I am trying to convert a structure with 40 fields into a single 3D matrix. I tried using struct2cell but got an error ??? Undefined function or method 'struct2cell' for input arguments of type 'double'.
I then tried creating a loop (below) but it writes the first field 40 times instead of writing all 40 fields once.. and I'm not sure how to fix it. The structure (runoff) has 40 fields, each with dimensions 12x360x720. I want to create a matrix (runoff_all) that has all the data in the structure and dimensions 480x360x720. How can I achieve this?
varnames=fieldnames(runoff);
runoff_all=zeros(480,360,720);
for k=1:length(varnames)
for i=1:12:469
runoff_all(i:i+11,:,:)=runoff.(varnames{k})(1:12,:,:);
end
end
  1 个评论
Walter Roberson
Walter Roberson 2012-4-24
Please show the call you tried for struct2cell()

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-4-24
'struct2cell' - built-in function of MATLAB
>> which struct2cell
about loop for .. end
varnames=fieldnames(runoff);
runoff_all=zeros(480,360,720);
for k=1:length(varnames)
frunoff_all(12*k + (-11:0),:,:)=runoff.(varnames{k});
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by