find index of a element present in matrix

1 Ansicht (letzte 30 Tage)
anakhi hazarika
anakhi hazarika am 20 Sep. 2019
Beantwortet: madhan ravi am 20 Sep. 2019
Hi...
I have a matrix A= [0 0 1 1; 1 0 0 1; 0 0 0 1]. I want to find the index of the first 1 of a row and want to save in a column matrix Z. In this case Z must be: Z=[ 3; 1; 4]. I am using this command Z = find(A(1,:), 1, 'first') but unable to do for second and third row. Kindly provide necessary codes for solving this.
Thank you.

Akzeptierte Antwort

madhan ravi
madhan ravi am 20 Sep. 2019
[~,Z]=max(A,[],2)

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays 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!

Translated by