Opening multiple fields within the same level of a structure

조회 수: 1 (최근 30일)
Gareth Pritchard
Gareth Pritchard 2014년 10월 13일
답변: Orion 2014년 10월 13일
I have a nested structure which after a couple of levels, reaches a level with each month of the year. Within each of these months I have 8 fields which contain 16x1 arrays of the type double. Is there a command I can use to open all 8 of these arrays in a month and have Matlab display them, rather than having to open them one by one?
Thank you

채택된 답변

Orion
Orion 2014년 10월 13일
Hi,
to access the fields of a structure you need to use fieldnames .
data.array1 = rand(16,1);
% ...
data.array8 = rand(16,1)+10;
allarray = fieldnames(data);
for i = 1:length(allarray)
% display array :
fprintf('%s\n',allarray{i})
disp(data.(allarray{i}))
end
and in case of a structure in a structure, you can do a for loop for each level

추가 답변 (0개)

카테고리

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