Clear Filters
Clear Filters

Creating a matrix based on sorted values from another matrix

1 view (last 30 days)
I have matrix A, 1X5, and matrix B, 1X5
% Matrix A
% Matrix B
I want to create matrx C, 2X5 as shown below,
% Matrix C 2X5
That is, to sort the data of matrix A in ascending order but at the same time have the corresponding value from matrix B. For example 0.0012 corresponds to 40.5 and etc. As shown in matrix C. How is this done?

Accepted Answer

Askic V
Askic V on 23 Feb 2023
[As, ind] = sort(A);
C = [As;B(ind)]

More Answers (0)


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!