How to group elements in arrays?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
bio lim
am 28 Mai 2015
Kommentiert: bio lim
am 2 Jun. 2015
Let's say I have a 1 x 5 structure array, 'data' with fields 'f1' 'f2' 'f3' 'f4' 'f5'. What I am trying to do is to group the elements of the array in f1 three by three, and find the corresponding mean of the elements in f2 - f5. Can anyone help me to do this? Thanks!
2 Kommentare
Murali Krishna
am 28 Mai 2015
can you clarify what do u mean by "group the elements of the array in f1 three by three"
Akzeptierte Antwort
Murali Krishna
am 28 Mai 2015
Bearbeitet: Murali Krishna
am 28 Mai 2015
I think this may solve ur problem
m=floor(length(data(1).f1)/3)
for l=1:1:length(data)
t=0;
for k=1:1:m
s1(l).a(k)=mean(data(l).f1(1+t:3+t));
s1(l).b(k)=mean(data(l).f2(1+t:3+t));
t=t+3;
end
end
I assume that the length of the fields f1 to f5 is same. check for structure s1.a,s1.b...for the mean of 3 elements of respective fields..
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!