필터 지우기
필터 지우기

How do I take repeat the calculation of average column?

조회 수: 2 (최근 30일)
tinkiewinkie
tinkiewinkie 2020년 6월 23일
댓글: tinkiewinkie 2020년 6월 24일
Hi suppose I have the above data, how do I repeat the calculation for the average column of data 1, data 2 and data 3 respectively suppose that the 0-4 means 0 to 4 seconds and 4-8 means 4 to 8 seconds and each data have different length. I wish to do this for 100 data. I wish to rename the data to just data1,data2 and data3...
my final result should be something as shown below:

채택된 답변

Rik
Rik 2020년 6월 23일
splitapply will do the trick. You can fairly easily find the number between 'data' and '--', so creating the group IDs shouldn't be too hard.
If you need help with implementing this, share the data instead of an image.
  댓글 수: 11
Rik
Rik 2020년 6월 24일
No, I meant this:
[num,str]=xlsread('output2.xlsx');
tokens=regexp(str,'sound([0-9]+)--','tokens');%capture the number as token
tokens=[tokens{:}];tokens=[tokens{:}];%unwrap
[~,IDs,G]=unique(str2double(tokens));%convert to positive integer
names=arrayfun(@(x) sprintf('sound%d',x),IDs,'UniformOutput',false);
output=splitapply(@(x) mean(x,1),num,G);
tinkiewinkie
tinkiewinkie 2020년 6월 24일
Yes thank you for your great help in this!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by