Mean of a field of a struct

9 ビュー (過去 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 Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by