フィルターのクリア

I am having trouble indexing

2 ビュー (過去 30 日間)
Leeba Ann Chacko
Leeba Ann Chacko 2022 年 6 月 6 日
コメント済み: Leeba Ann Chacko 2022 年 6 月 6 日
I have two 2x4 matrices A and B. I have rearranged A in decending order and have obtained the index for this rearrangement. I would like to use this index to rearrange B. However, when I try that, it is is only working for the 1st column and using the values from this column for the rest. How do I rectify this?
Here is my code:
A = rand(2,4);
B = rand(2,4);
[C,idx] = sort(A,'descend');
D=B(idx);

採用された回答

KSSV
KSSV 2022 年 6 月 6 日
A = rand(2,4);
B = rand(2,4);
[C,idx] = sort(A,'descend');
D=B;
for i = 1:size(idx,2)
D(:,i) = B(idx(:,i),i) ;
end
  1 件のコメント
Leeba Ann Chacko
Leeba Ann Chacko 2022 年 6 月 6 日
Thank you, this worked well for me! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by