How can I do loop for struct data?

I have a data set that consist of a structure , example: data (1x10 struct with 1 field) How can I do loop to read all these data? I want to be able to do a calculation on a specific measurements of each field. Thanks

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 18일

0 개 추천

a=struct('f',num2cell(1:10))
out=[a.f]

댓글 수: 6

Riyadh Muttaleb
Riyadh Muttaleb 2016년 4월 18일
편집: Riyadh Muttaleb 2016년 4월 18일
Thank you for your response. I have matrix data (numerical fields), your answer gave me just numbers from 1 to 10. How can I read matrices data?
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 18일
Post an example
v=num2cell(rand(4))
a=struct('f',v)
%-------------------------
out=reshape([a.f],size(a))
Riyadh Muttaleb
Riyadh Muttaleb 2016년 4월 20일
Hello Azzi, Thank you for your cooperation.. here exactly what I have. I have file (data.mat) consists of file named(FS (1X10 struct with one field)) . these ten file as matrices (4000X234). I would like to read them and apply an equation (any equation as example). That will help me a lot in my research.
Thank you
Riyadh
suppose you have this matrix
A=[1 2;3 4;5 6]
What operation you want to apply?
Riyadh Muttaleb
Riyadh Muttaleb 2016년 4월 21일
b=2/3*A(i,j)
Walter Roberson
Walter Roberson 2016년 4월 19일

0 개 추천

Example:
arrayfun(@(IDX) mean(YourStructArray(IDX).TheField(:)), 1:numel(YourStructArray))

이 질문은 마감되었습니다.

태그

질문:

2016년 4월 18일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by