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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2016 年 8 月 3 日

コメント済み:

2016 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by