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

1 visualización (últimos 30 días)
Varghese
Varghese el 4 de Ag. de 2022
Editada: Matt J el 4 de Ag. de 2022
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.

Respuesta aceptada

Matt J
Matt J el 4 de Ag. de 2022
Editada: Matt J el 4 de Ag. de 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

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by