Use index from max() to extract matching values from another array
3 ビュー (過去 30 日間)
古いコメントを表示
Suppose I have 2 n x m arrays A and B and I get the maximum element of each column of A with
[~,I] = max(A)
Now I want to use I to extract the elements of B that correspond to the max element of each column of A.
For example (the example itself is of no particular interest)
A = rand(5)
B = A.^2
[~,I] = max(A)
Now I would like to have a one line command that extracts from B a row vector consisting of, for each j, the I'th element of column j.
Thanks!
0 件のコメント
採用された回答
David Young
2014 年 12 月 16 日
Bmax = B(sub2ind(size(B), I, 1:size(B,2)))
4 件のコメント
Ram
2018 年 7 月 29 日
編集済み: Ram
2018 年 7 月 29 日
thanks for responding, attached file as max with its indexand mydata has to find those index values and place it to a new cell. for example, i have index value 690, i am finding in mydata which has (8.1510,110.9065) but i need only first col value only for every index.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!