MATLAB: Arrays sorting

arrayssort

Hello,
I have 2 arrays: A=[3 5 11] and B=[2 3 0]. I multiply these 2 arrays and I produce a third: C=times(A,B)=[6 15 0]. I sort array C in descent order D=sort(C,'descend')=[15 6 0]. How can I sort and the arrays A and B to match with array D? I mean I want array A to take this order:A=[5 3 11] and array B=[3 2 0]. But, I want this function to work for random arrays and not only for the example!
Thank you…

Best Answer

A = [3 5 11]
B = [2 3 0]
C = times(A, B);
[D, Index] = sort(C);
AA = A(Index)
BB = B(Index)