How to find the column index of the first nonzero element for every row of a given matrix
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear all,
I have the following matrix
A=[1 1 1 1; 0 1 1 1; 0 0 0 1; 0 0 1 1; 0 1 1 1]
and I would like to get an output vector v listing the column indices of the first nonzero element for every row of A:
v=[1;2;4;3;2]
How can I do this? Thanks in advance, I appreciate your time and help.
2 Commenti
Risposta accettata
Arif Hoq
il 6 Mar 2022
you can find your answer here
Just follow this:
A=[1 1 1 1; 0 1 1 1; 0 0 0 1; 0 0 1 1; 0 1 1 1];
[~,output]=max(A,[],2)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!