sum of consecutive events below a threshold

조회 수: 2 (최근 30일)
Mustapha Adamu
Mustapha Adamu 2019년 5월 5일
댓글: Mustapha Adamu 2019년 5월 6일
M = [-2,1,4,-1,-3,-4,3, 3, 1,-2, -3,-1,-3,]
I have an array like M above, I want to find where consecutive numbers are less than -1, and find their mean as well as count:
In this case my first event will be np.mean (-1,-3,-4) and count will be 3 and second will be np.mean (-2,-3,-2,-3) then count will be 4
Thanks in advance
  댓글 수: 2
dpb
dpb 2019년 5월 5일
Either M is mistyped or the second result is wrong...I suppose you meant
M = [-2,1,4,-1,-3,-4,3, 3, 1,-2,-3,-2,-3,]
not
M = [-2,1,4,-1,-3,-4,3, 3, 1,-2, -3,-1,-3,]
as given?
How is this Q? any different than the one you posted just 20 min or so earlier at https://www.mathworks.com/matlabcentral/answers/460360-finding-the-mean-sum-of-consecutive-dry-days-below-1
Remove one or the other; don't post multiple times for the same question if somebody doesn't answer instantaneously.
Mustapha Adamu
Mustapha Adamu 2019년 5월 5일
Thw other one removed, thanks and was mistyped in the first case

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

답변 (1개)

Image Analyst
Image Analyst 2019년 5월 5일
If you have the Image Processing Toolbox, try this:
M = [-2,1,4,-1,-3,-4,3, 3, 1,-2, -3,-1,-3,]
binaryM = M <= -1 % Find locations where M <= -1
props = regionprops(binaryM, 'Area') % Make the counts
counts = [props.Area] % Concatenate all from structure into array.
% Get rid of single counts, where counts == 1
% like when M was = to -2 at the beginning.
counts(counts == 1) = []
Result is
counts =
3 4
  댓글 수: 2
Mustapha Adamu
Mustapha Adamu 2019년 5월 5일
I dont have Image processing toolbox unfortunatly is I will try to get Image processing toolbox, but in the mean time is there another way?
Mustapha Adamu
Mustapha Adamu 2019년 5월 6일
Hi I got the image processing tool box and now its working fine, Another question that I have though is that how if I want to do this in a loop say from 1-60, from 2-61, from 3-62 etc etc

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by