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

2 次查看(过去 30 天)
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?

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2018-2-6
The easiest way:
varfun(@mean, yourtable, 'GroupingVariables', {'sub', 'window'}, 'InputVariables', {'mean', 'stdev', 'rms'})

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by