How to sort matrix based on another matrix?
Show older comments
A=[3,2,1;8,3,1;6,4,2] and B=[5,9,2;9,2,1;8,7,4] Matrix A sort by row like A=[1,2,3;1,3,8;2,4,6] then based on A change values of B matrix like B=[2,9,5;1,9,2;4,7,8].
Accepted Answer
More Answers (1)
Rik
on 26 Aug 2019
Assuming you made a small typo in your B_out:
A=[3,2,1;8,3,1;6,4,2];
B=[5,9,2;9,2,1;8,7,4];
for row=1:size(A,1)
[A(row,:),order]=sort(A(row,:));
B(row,:)=B(row,order);
end
clc,disp(B)
1 Comment
K Venkatesh
on 26 Aug 2019
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!