Get average of all rows in table that match two exact strings

2 ビュー (過去 30 日間)
Centauri Jolene
Centauri Jolene 2018 年 2 月 6 日
コメント済み: Centauri Jolene 2018 年 2 月 6 日
I have a table that is formatted like this:
sub type window mean stdev rms
_____ ____ ______ _______ ______ ______
'S03' 'e4' 'w1' -0.6357 0.3274 0.715
'S03' 'e4' 'w1' -0.591 0.3106 0.6676
'S03' 'e4' 'w2' -0.4616 0.3607 0.5857
'S03' 'e4' 'w2' -0.457 0.3387 0.5687
'S03' 'e4' 'w2' -0.5737 0.2689 0.6335
'S03' 'e4' 'w3' -0.4818 0.2139 0.5271
'S03' 'e4' 'w3' -0.4272 0.1523 0.4536
'S06' 'e4' 'w1' -0.6357 0.3274 0.715
'S06' 'e4' 'w2' -0.591 0.3106 0.6676
'S06' 'e4' 'w2' -0.4616 0.3607 0.5857
'S06' 'e4' 'w2' -0.457 0.3387 0.5687
'S06' 'e4' 'w2' -0.5737 0.2689 0.6335
'S06' 'e4' 'w3' -0.4818 0.2139 0.5271
For each subject (e.g. S03 & S06 shown above) I need to get the average mean, stdev, and rms for each window (3 windows shown above: w1-w3).
So I need to check the subject string (1st col) and the window string (3rd col) to check if the rows belong to the same subejct and window, and then calculate the average values for the mean, stdev, and rms columns.
The data is attached as a .mat file.
I've tried the following but cant get it to work:
rowssub = any(strcmp(accStats,'S03'),1);
rowsw = any(strcmp(accStats,'w1'),1);
The result ends up being a 1x1 logical with value of 0.
  2 件のコメント
Jan
Jan 2018 年 2 月 6 日
It would be much easier to post a solution, if the readers can test a suggestion with input data. Posting the data as mat file or as code, which can be run by copy&paste, would be very helpful.
Please post the code you have tried so far and explain "cant seem to get it to work" with details. Maybe you had a typo only and the error message reveals the problem?
While the average mean has a specific physical meaning, are you sure that an average of the standard deviations is meaningful?
Centauri Jolene
Centauri Jolene 2018 年 2 月 6 日
Thanks, I edited above.

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

採用された回答

Guillaume
Guillaume 2018 年 2 月 6 日
The easiest way:
varfun(@mean, yourtable, 'GroupingVariables', {'sub', 'window'}, 'InputVariables', {'mean', 'stdev', 'rms'})
  1 件のコメント
Centauri Jolene
Centauri Jolene 2018 年 2 月 6 日
Perfect and so much simpler than I anticipated. Thanks!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by