Select positive values around a certain value

Hi there,
I want to select a specific string in an array containing positive and negative values.
For example:
A = [-2 1 0.5 -34 4 5 9 3 1 -3 -2 6 -7]
B = 3
I want to select the positive points surrounding A(8) = 3.
So A(5:9).
Best regards and thank you in advance!

 채택된 답변

Rik
Rik 2019년 10월 2일

2 개 추천

If you happen to have the image processing toolbox:
A = [-2 1 0.5 -34 4 5 9 3 1 -3 -2 6 -7];
B = 3;
labeled=bwlabel(A>0);
L=labeled==labeled(A==B);
ind=find(L);
If not, there are several alternative methods you could try.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2019년 10월 2일

댓글:

2019년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by