Hi,
Let us suppose arrays A and B:
A = [1 9 6 2 10 8 3 8 11 7 5 5 6]B = [1 2 2 1 1 1 1 1 2 2 2 2 2]
I want to create an array C that randomly puts all element of array A with identical values in array B together (with out chanding the order of identical elements in array A). For example, the array C can be as follows:
C = [1 2 10 8 3 8 9 6 11 7 5 5 6]C = [9 6 11 7 5 5 6 1 2 10 8 3 8]% where the first group with identical values in B is [1 2 10 8 3 8]
% and the second group is [9 6 11 7 5 5 6]
Now, let me clarify how the array C can be generated. First, I need to detect the uniqe values in the array B, which will be:
D = [1 2]
Then, I need to randomly sort the array D. Then, I will use the elements in sorted D to generate the array C as follows:
C = [A(B == D(1)) A(B == D(2))]
What would be the most efficient way for doing this action?
Many thanks for your attention, Amirhossein
Best Answer