MATLAB Answers

0

How to find the index in array?

Meshooo 님이 질문을 제출함. 3 Aug 2016
최근 활동 Meshooo 님이 댓글을 추가함. 4 Aug 2016
Dear all,
I have the following array A = [0;0;0;0;0;0;1;1;;0;0;0;0];
I want to find the right and left index of the 1's? In this case
Left_A = 7
Right_A = 8
In another situations, A = [0;0;0;0;0;0;1;0;0;1;0;0;0];
Left_A = 7
Right_A = 10
Any idea how to do that? Thank you very much.
Meshoo

  댓글 수: 0

로그인 to comment.

답변 수: 1

Adam 님의 답변 3 Aug 2016
 채택된 답변

Left_A = find( A == 1, 1 );
Right_A = find( A == 1, 1, 'last' );

  댓글 수: 1

That works very well. Thank you very much.

로그인 to comment.



Translated by