How to find the index in array?

조회 수: 1 (최근 30일)
Meshooo
Meshooo 2016년 8월 3일
댓글: Meshooo 2016년 8월 4일
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

채택된 답변

Adam
Adam 2016년 8월 3일
Left_A = find( A == 1, 1 );
Right_A = find( A == 1, 1, 'last' );
  댓글 수: 1
Meshooo
Meshooo 2016년 8월 4일
That works very well. Thank you very much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by