How find the row number for different elements in a column?

1 visualizzazione (ultimi 30 giorni)
Suppose I set a condition where I choose only a certain element from each column. Now how will I get the row number corresponding to each element I have selected from each column. Note that the result should be an array with n elements, where n= number of columns.

Risposta accettata

Matt J
Matt J il 4 Ago 2022
Modificato: Matt J il 4 Ago 2022
As an example, suppose you wanted to find the first occurrence of a 2 in each column. Then one way would be,
A=randi(10,10,5)
A = 10×5
6 8 9 6 2 9 9 2 5 10 4 7 2 5 10 5 5 9 3 1 8 1 8 7 7 6 3 4 1 2 5 2 7 10 10 2 3 8 1 9 3 9 8 9 7 1 2 3 7 4
[~,firstInstance]=max(A==2)
firstInstance = 1×5
8 7 2 1 1

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices 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!

Translated by