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

1 回表示 (過去 30 日間)
Varghese
Varghese 2022 年 8 月 4 日
編集済み: Matt J 2022 年 8 月 4 日
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.

採用された回答

Matt J
Matt J 2022 年 8 月 4 日
編集済み: Matt J 2022 年 8 月 4 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by