I need to implement the following algorithm in Matlab.
- Suppose
A = [3 4 1 9 5] - permute
Arandomly say,A = [5 1 4 3 9] - Add 2 to the first two elements:
A = [7 3 4 3 9] - permute A back,
A = [3 4 3 9 7]
I am using randperm() function to permute:
index = randperm(numel(A));
A = A(index);
But the problem is how to permute it back, after changing array A to the first permutation.
You can actually put the indexing on the left hand side:
😉