Check values under a certain threshold with an undefined window

조회 수: 4 (최근 30일)
bfenst
bfenst 2018년 4월 13일
답변: Image Analyst 2018년 4월 13일
Hello all,
I am new to Matlab. I have a large vector called A (over 400000 values). I would like to find the maximum value of that vector then look for values that are 10 % around the maximum.
Here is an example:
A=[9 10 47 50 49 48 2 46];
mymax=max(A); % in this case mymax=50
mincondition=mymax*0.9; % mincondition=45
Then I should be able to get all values around A(4)=50 that are over mincondtion. The window of considered values stops when mincondition is no longer surpassed. In this case, the results would be:
res=[47 50 49 48];
Can anyone please help me?
Thank you.
  댓글 수: 2
David Fletcher
David Fletcher 2018년 4월 13일
Why isn't the 46 (last element) included in res? (sorry I didn't really understand what you mean by 'the window of considered values stops when mincondition is no longer surpassed' - I am just assuming that you want everything from A that is over mincondition)
bfenst
bfenst 2018년 4월 13일
Thank you for checking my question. I want everything from A that is over mincondition AND that is consecutive to the max or the values that are over mincondition.
That is why 46 is not included in the res.

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

채택된 답변

David Fletcher
David Fletcher 2018년 4월 13일
A=[9 10 47 50 49 48 2 46];
mymax=max(A); % in this case mymax=50
mincondition=mymax*0.9; % mincondition=45
indexer=A>mincondition
[start,stop]=regexp(char(indexer+48),'1+')
res=A(indexer(1:stop(1)))
It's probably worth checking it works thoroughly - I kept getting disturbed by people actually wanting me to do some work while I was writing it.
  댓글 수: 1
bfenst
bfenst 2018년 4월 13일
Thank you very much, it is exactly what I needed. Impressive how a few lines of code do the deed, I was at 30 lines trying to achieve with no results.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 4월 13일
Here's one way using morphological reconstruction:
A = [9 10 47 50 49 48 2 46];
mask = A >= 0.9 * max(A)
indexes = imreconstruct(A == max(A), mask) % Requires Image Processing Toolbox.
finalValues = A(indexes)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by