I have 2 matrices as follows:
a_lab = [4, 3, 5, 6, 7, 1;
1, 2, 3, 4, 6, 1;
4, 5, 3, 2, 1, 5];
a = [0.6, 0.4, 0.1, 0.05, 0.01, 0.2;
0.16, 0.4, 0.1, 0.15, 0.01, 0.22;
0.6, 0.24, 0.11, 0.05, 0.11, 0.2];
I sort 'a' row-wise and obtain the indices:
[a_sorted, idx] = sort(a, 2, 'descend');
0.6000 0.4000 0.2000 0.1000 0.0500 0.0100
0.4000 0.2200 0.1600 0.1500 0.1000 0.0100
0.6000 0.2400 0.2000 0.1100 0.1100 0.0500
I now want to sort a_lab using idx, so the matrices a and a_lab stay in registration. I can sort one row of a_lab using one row of idx, like this:
a_lab_sorted = a_lab(1, idx(1, :));
But, how can I sort all rows of a_lab in one go (without a for loop)? This:
a_lab_sorted = a_lab(:, idx);
...is not correct, it produces a 3x18 matrix. Thanks.
The other question suggested as a duplicate uses a for loop. I am asking for a non-loop solution. Thanks.