Calculating Means for Blocks of Data from Excel

1 Ansicht (letzte 30 Tage)
Julian Dale
Julian Dale am 22 Jun. 2019
Kommentiert: Julian Dale am 22 Jun. 2019
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.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 22 Jun. 2019
Bearbeitet: Andrei Bobrov am 22 Jun. 2019
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 Kommentar
Julian Dale
Julian Dale am 22 Jun. 2019
Hi Andrei,
That's great.
Thank you for the quick response and for your help.
Julian

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by