How to call the row number of an element?
39 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Varghese
am 3 Aug. 2022
Bearbeitet: Matt J
am 3 Aug. 2022
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 Kommentare
Akzeptierte Antwort
Veronica Taurino
am 3 Aug. 2022
Bearbeitet: Veronica Taurino
am 3 Aug. 2022
%[row,col] = find(__)
For example:
X = [1 0 2; 0 1 1; 0 0 4]
[row,col] = find(X==4)
0 Kommentare
Weitere Antworten (1)
Matt J
am 3 Aug. 2022
Bearbeitet: Matt J
am 3 Aug. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!