Find median position points of duration events

I have the following vector A:

A = [34 35 36 5 6 7 78 79 7 9 10 80 81 82 84 85 86 102 3 4 6 103 104 105 106 8 11 107 201 12 202 203 204];

For n = 2 , I counted the elements larger or equal to 15 within A :

D = cellfun(@numel, regexp(char((A>=15)+'0'), [repmat('0',1,n) '+'], 'split'));

The above expression gives the following output as duration values:

D = [3 2 7 4 6] = [A(1:3) **stop** A(7:8) **stop** A(12:18) **stop** A(22:25) **stop** A(28:33)];

The above algorithm computes the duration values by counting the elements larger or equal to 15. The counting also allows less than 2 consecutive elements smaller than 15 ( n = 2 ). The counter stops when there are 2 or more consecutive elements smaller than 15 and starts over at the next substring within A .

Eventually, I want a way to find the median position points of the duration events A(1:3) , A(7:8) , A(12:18) , A(22:25) and A(28:33) , which are correctly computed. The result should look like this:

a1 = round(median(A(1:3))) = 2; 
a2 = round(median(A(7:8))) = 8;
a3 = round(median(A(12:18))) = 15;
a4 = round(median(A(22:25))) = 24;
a5 = round(median(A(28:33))) = 31;

I edited the question to make it more clear, because the solution that was provided here assigns the last number within the row of 2 or more consecutive numbers smaller than 15 (3 in this case) after A(1:3) to the next substring A(7:8) and the same with the other substrings, therefore generating wrong duration values and in consequence wrong median position points of the duration events when n = 2 or for any given even n .

Anyone has any idea how to achieve this?

链接地址: http://www.djcxy.com/p/83832.html

上一篇: 如何用ng迭代键和值

下一篇: 查找持续时间事件的中间位置点