Calculating Means for Blocks of Data from Excel

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

类别

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