Mean of a field of a struct

조회 수: 10 (최근 30일)
FG
FG 2020년 9월 13일
댓글: Ameer Hamza 2020년 9월 15일
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..

답변 (2개)

Matt J
Matt J 2020년 9월 13일
C=struct2cell(rmfield(S,'name'));
A=cell2mat(reshape(C,1,4,[]));
Averages = reshape( mean(A,1),4,[]).'
  댓글 수: 3
Matt J
Matt J 2020년 9월 13일
편집: Matt J 2020년 9월 13일
[array2table({S.name}.'),array2table(Averages)]
FG
FG 2020년 9월 14일
Thanks Matt..

댓글을 달려면 로그인하십시오.


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

댓글을 달려면 로그인하십시오.

카테고리

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