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
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
2018년 2월 6일
The easiest way:
varfun(@mean, yourtable, 'GroupingVariables', {'sub', 'window'}, 'InputVariables', {'mean', 'stdev', 'rms'})
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!