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

1 vue (au cours des 30 derniers jours)
Centauri Jolene
Centauri Jolene le 6 Fév 2018
Commenté : Centauri Jolene le 6 Fév 2018
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 commentaires
Jan
Jan le 6 Fév 2018
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 le 6 Fév 2018
Thanks, I edited above.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 6 Fév 2018
The easiest way:
varfun(@mean, yourtable, 'GroupingVariables', {'sub', 'window'}, 'InputVariables', {'mean', 'stdev', 'rms'})
  1 commentaire
Centauri Jolene
Centauri Jolene le 6 Fév 2018
Perfect and so much simpler than I anticipated. Thanks!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by