How can I rearrange an array in MATLAB by a specific rule?

Viewed 119

Suppose that I have this array:

a = [1,2,3,4,5];

The output should be something like this:

1,2,3,4,5
2,1,3,4,5
3,1,2,4,5
4,1,2,3,5
5,1,2,3,4

how Can I do this? This function should be valid for different lengths of a.

4 Answers
Related