Mean of a field of a struct

10 Ansichten (letzte 30 Tage)
FG
FG am 13 Sep. 2020
Kommentiert: Ameer Hamza am 15 Sep. 2020
As seen in image below, I have a struct of 5 fields. I need to compute the avarege of the HV3, HV5, HV7 and thd in 1st row, then in the second row and so on seperately.. Have a nice weekend..

Antworten (2)

Matt J
Matt J am 13 Sep. 2020
C=struct2cell(rmfield(S,'name'));
A=cell2mat(reshape(C,1,4,[]));
Averages = reshape( mean(A,1),4,[]).'
  3 Kommentare
Matt J
Matt J am 13 Sep. 2020
Bearbeitet: Matt J am 13 Sep. 2020
[array2table({S.name}.'),array2table(Averages)]
FG
FG am 14 Sep. 2020
Thanks Matt..

Melden Sie sich an, um zu kommentieren.


Ameer Hamza
Ameer Hamza am 13 Sep. 2020
Try something like this
S_new = rmfield(S, 'name');
S_out = arrayfun(@(s) structfun(@mean, s, 'uni', 0), S_new);
[S_out.name] = S.name;
  8 Kommentare
FG
FG am 15 Sep. 2020
Thank you Ameer.. I just need to write it to excel, job's done !
Ameer Hamza
Ameer Hamza am 15 Sep. 2020
I am glad to be of help!

Melden Sie sich an, um zu kommentieren.

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