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 Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by