finding nonzero elements in matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tilek Zhumabek
am 10 Feb. 2020
Bearbeitet: KSSV
am 11 Feb. 2020
Hello,
I have a matrix with the values of either zero or one; I want to find non zero elements in every coloumn and locate the indices of each non zero element in every coloumn of a new matrix. For example, let's say my original matrix looks like this:
a =
0 1 1
0 0 1
1 1 1
I want the indices of non zero element in a new matrix look like this:
b =
0 1 1
0 0 2
3 3 3
How can I do it? I tried with the find function but without any success.
Thanks in advance,
Tilek
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 10 Feb. 2020
Use implicit expansion.
A = [0 1 1; 0 0 1; 1 1 1];
R = (1:size(A, 1)).';
B = A.*R
Siehe auch
Kategorien
Mehr zu Spline Postprocessing 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!