Finding column index of the first instance of 1
5 ビュー (過去 30 日間)
古いコメントを表示
I have a logical array like this:
I want to extrat the colum index of the cells where the first instance of 1 is detected. Like this:
For example, you see here that the first two rows show 4, because that is where 1 is first detected.
0 件のコメント
採用された回答
Walter Roberson
2022 年 5 月 2 日
C = sum(cumprod(~X, 2),1) + 1;
C will be one more than the number of columns for any row that has no 1.
4 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!