MATLAB Answers

Field of a structure

3 views (last 30 days)
FG
FG on 8 Sep 2020
Commented: FG on 8 Sep 2020
As Stephen Cobeldick helped me yesterday, I have a structure T consisting of 4 fields. I want to calculate the mean of each field in T.. Then I want all them to be written in an excel file. Thnx..

  2 Comments

Rik
Rik on 8 Sep 2020
What did you try yourself?
FG
FG on 8 Sep 2020
Tried this but did'nt work.. M = mean([T.HV3])

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 8 Sep 2020
M = mean(T.HV3)
and then use writematrix.

  2 Comments

FG
FG on 8 Sep 2020
It gives a NaN
FG
FG on 8 Sep 2020
Guess I found it..

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 8 Sep 2020
D = structfun(@mean, T);
writetable(table(D), 'Sample.xlsx') % or writematrix() as Stephen suggested

  0 Comments

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!