Re-arranging row of a matrix in array.
1 view (last 30 days)
Show older comments
Commented: Telema Harry on 1 Apr 2021
I am trying to perform the following tasks.
- I have a function that returns two vector as output and one of the vector must be arranged in ascending order for further computation.
- The second vector would also need to be rearranged such that each element corresponds to the other vector origal element.
[A, B] = Executeprogram(C,D);
% The output of A & B are given below.
% The objective is to arrange A in ascending order such that each element
% of B will still correspond to A
A = 2, 5, -3, 10;
B = 3, 1, 4, 2;
% I want the final answer to be like
% A = -3,2,5,10
% B = 4, 3,1,2
Please how can I perform this tasks in MATLAB?
KSSV on 1 Apr 2021
A = [2, 5, -3, 10];
B = [3, 1, 4, 2];
[A,idx] = sort(A)
B = B(idx)
More Answers (1)
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!