Mean of a field of a struct

5 visualizaciones (últimos 30 días)
FG
FG el 13 de Sept. de 2020
Comentada: Ameer Hamza el 15 de Sept. de 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..

Respuestas (2)

Matt J
Matt J el 13 de Sept. de 2020
C=struct2cell(rmfield(S,'name'));
A=cell2mat(reshape(C,1,4,[]));
Averages = reshape( mean(A,1),4,[]).'
  3 comentarios
Matt J
Matt J el 13 de Sept. de 2020
Editada: Matt J el 13 de Sept. de 2020
[array2table({S.name}.'),array2table(Averages)]
FG
FG el 14 de Sept. de 2020
Thanks Matt..

Iniciar sesión para comentar.


Ameer Hamza
Ameer Hamza el 13 de Sept. de 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 comentarios
FG
FG el 15 de Sept. de 2020
Thank you Ameer.. I just need to write it to excel, job's done !
Ameer Hamza
Ameer Hamza el 15 de Sept. de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by