필터 지우기
필터 지우기

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