How do I record the location of a specific value in a set of data?
1 回表示 (過去 30 日間)
古いコメントを表示
Madison Castellanos
2020 年 6 月 17 日
コメント済み: Madison Castellanos
2020 年 6 月 18 日
Hello,
I am very new to matlab, and would appreciate advice!
I understand my question is not entirely clear. So I am trying to go through data that looks like:
[1] 0 0 0 0 1 0 1 0 0
And want the code to index until it encounters the first 1 (ignoring the rest of the 1s repeated in the row) then state the distance from the start of the row to the first 1 [so here it would be the distance from column 5 to column 1]
Then ideally it would repeat the same thing for a second row. My 'for' loop is not working, and ideally this code would work for dozens of rows of data. Thank you :)
0 件のコメント
採用された回答
madhan ravi
2020 年 6 月 17 日
First_1 = find(x,1) % where x is your row in the loop
Distance = diff(find(x,2))
3 件のコメント
madhan ravi
2020 年 6 月 18 日
That is why I specifically commented saying “row” which is “singular”. Loop through through the rows. Preallocate distance as a cell.
その他の回答 (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!