struct array

18 Ansichten (letzte 30 Tage)
Richard
Richard am 8 Jan. 2012
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).

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 8 Jan. 2012
d = [Name;Temp];
Data = struct(d{:})

Weitere Antworten (1)

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

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by