How to call the row number of an element?
43 ビュー (過去 30 日間)
古いコメントを表示
suppose I find a value after applying some formula and then need to find the row/column in the matrix where the value appears.
How do I do this?
0 件のコメント
採用された回答
Veronica Taurino
2022 年 8 月 3 日
編集済み: Veronica Taurino
2022 年 8 月 3 日
%[row,col] = find(__)
For example:
X = [1 0 2; 0 1 1; 0 0 4]
[row,col] = find(X==4)
0 件のコメント
その他の回答 (1 件)
Matt J
2022 年 8 月 3 日
編集済み: Matt J
2022 年 8 月 3 日
With find, but be mindful that direct logical indexing is often faster if you are seeking to modify the matrix. Compare:
%Replace all A(i,j)>=50 with 3
A=randi(100,5e3,5e3);
tic;
I=find(A>=50);
B0=A;
B0(I)=3;
toc
tic;
B=A;
B(A>=50)=3;
toc
isequal(B0,B)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!