struct array

조회 수: 18 (최근 30일)
Richard
Richard 2012년 1월 8일
I'm attempting to do the following inside a loop:
Name={'Note1','Note2','Note3','Note4'};
Data=struct('Note1',Temp{1,1},'Note2',Temp{1,2},'Note3',...
Temp{1,3},'Note4',Temp{1,4});
Is it possible to do this inside a loop, therefore avoiding to writing each individual field name: Something like the following, although this provides an error: for i=1:4; Data(i)=struct(Name{i},Temp{1,i}); end
I'm thinking that the problem lies with Data(i).

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 1월 8일
d = [Name;Temp];
Data = struct(d{:})

추가 답변 (1개)

David Young
David Young 2012년 1월 8일
for i=1:4
Data.(Name{i}) = Temp{1,i};
end

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by