Calculating Means for Blocks of Data from Excel

조회 수: 1 (최근 30일)
Julian Dale
Julian Dale 2019년 6월 22일
댓글: Julian Dale 2019년 6월 22일
I have some EMG data that I have processed and now have in an Excel file.
Within the excel file I have used an IF statement to identify whether the signal is above a set threshold in which case it is of interest. I would then like to take the mean for each block of data that the signal is active.
Probably eassiest to explain this with an exapmle (numbers selected to make exaple simple to understand):
Let's say that I had the following data set:
2 1 2 3 5 8 6 9 4 3 2 3 2 1 4 6 7 8 9 6 3 2
Now let's say that the threshold for activity is greater than or equal to 4, (If statement in excel provides 0, but could be false or blank), so I would get:
0 0 0 0 5 8 6 9 4 0 0 0 0 0 4 6 7 8 9 6 0 0
I would like to know the avaerge of the two active periods.
i.e. mean [ 5 8 6 9 4] and [4 6 7 8 9 6], is this possible with Matlab and if so, how would I go about it?
Any help would be greatly appreciated.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 6월 22일
편집: Andrei Bobrov 2019년 6월 22일
A = [2 1 2 3 5 8 6 9 4 3 2 3 2 1 4 6 7 8 9 6 3 2];
lo = A(:) >= 4;
loo = cumsum([0;diff(lo)==1]).*lo;
lo3 = loo > 0;
out = accumarray(loo(lo3),A(lo3),[],@mean);
  댓글 수: 1
Julian Dale
Julian Dale 2019년 6월 22일
Hi Andrei,
That's great.
Thank you for the quick response and for your help.
Julian

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

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by