I have A (3*5) matrix. I have B(14*6) matrix.
Now I want C (14*5) matrix from A and B in such a way that column 2 and 3 for each row of matrix B will be replaced by corresponding cell value of A.
For example – column 2 and 3 of 1st row of B is 1 and 4. Then we need to find the value of A(1,4) which is 10. This 10 will be second column value for 1st row of matrix C.
C(:,1)= B(:,1) ; C(:,2) = from above condition; C(:,3) = B(:,4); C(:,4) = B(:,5) ; C(:,5) = B(:,6)
Eventually, I want matrix D(14*5) from C with the second column value sorted from highest to lowest. Then all the rows in column 1, 3, 4, and 5 will be according to corresponding second column.
Can anyone please help me how to get this D matrix from A and B? I have attached A, B, C, and D matrix here for the clarification.
My B matrix row number is much larger in real case. I just made it smaller here to simplify the problem. Matrix A (3*5) is fixed.
Thanks in advance.
A=[13 12 11 10 313 9 8 7 213 6 5 4 1];B=[1 1 4 0 3 22 1 2 2 0 23 1 2 0 5 04 2 2 3 2 05 3 5 3 0 26 3 4 0 0 57 2 5 3 2 08 2 4 0 3 09 2 3 0 2 310 3 2 0 3 211 3 3 0 0 512 1 3 0 5 013 1 1 1 2 214 1 5 0 2 2];C=[1 10 0 3 22 12 2 0 23 12 0 5 04 9 3 2 05 1 3 0 26 4 0 0 57 2 3 2 08 7 0 3 09 8 0 2 310 6 0 3 211 5 0 0 512 11 0 5 013 13 1 2 214 3 0 2 2];D=[13 13 1 2 22 12 2 0 23 12 0 5 012 11 0 5 01 10 0 3 24 9 3 2 09 8 0 2 38 7 0 3 010 6 0 3 211 5 0 0 56 4 0 0 514 3 0 2 27 2 3 2 05 1 3 0 2];
Best Answer