I wouldn't call this an algorithm. It's just indexing. If something more robust is needed we'll need a more detailed description or set of rules to follow.
A = [1, 2, 3, 4, 5, 6];
A = A([1,3,2,4,5,6])
A = 1×6
1 3 2 4 5 6
> Vector A is a vector of unknown length and content, in which the k-th and j-th elements change.
Best Answer