フィルターのクリア

Calculate multiple means in table by column indices

2 ビュー (過去 30 日間)
Robin Schäfer
Robin Schäfer 2020 年 3 月 6 日
コメント済み: Robin Schäfer 2020 年 3 月 6 日
Hello community,
I want to calculate means of several parameters in my table according to row indices. Here is what my table now looks like:
Subject Phase Time Par1 Par2 Par3 ...
__________________ ___________________ ____________ _____________ ______ _____________ _____________
{'Name1' } {'Phase1' } {'00:17:05'} 1614.7 1.1787 136.33 ...
{'Name2' } {'Phase1' } {'00:17:05'} 496.2 1.091 35.379 ...
{'Name1' } {'Phase2' } {'00:15:05'} 1535.4 1.2158 127.32 ...
{'Name2' } {'Phase2' } {'00:15:05'} 1084.9 1.1678 82.798 ...
... % 98x9 table
The output should be a table:
Phase Time Par1 Par2 Par3 ...
___________________ ____________ _____________ ______ _____________ _____________
{'Phase1' } {'00:17:05'} % mean values of all subjects in Phase1 ...
{'Phase2' } {'00:15:05'} % mean values of all subjects in Phase2 ...
... % 98x9 table
I calculated the mean with varfun of a single parameter (see underneath). However, I think there has to be a simple solution calculating the mean of multiple parameters without using for-loops and merging the output...
NewTable=varfun(@nanmean,Table,'InputVariables','Par1','GroupingVariables','Phase');

採用された回答

Guillaume
Guillaume 2020 年 3 月 6 日
編集済み: Guillaume 2020 年 3 月 6 日
newtable = groupsummary(yourtable, {'Phase', 'Time'}, 'mean', 4:width(yourtable)) %mean of all but the first 3 variables, grouped by Phase and Time
Hopefully your table is not called Table but something more descriptive.
  1 件のコメント
Robin Schäfer
Robin Schäfer 2020 年 3 月 6 日
Thank you for your very fast response! Works fine! I've renamed everything for this post and names are more precise in my functions =)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by