Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

arrays

matlab

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.

like image 887
Eghbal Avatar asked Dec 02 '22 12:12

Eghbal


1 Answers

Using combinatory:

b = [a.' flipud(nchoosek(a,numel(a)-1))];
like image 150
Leander Moesinger Avatar answered Dec 21 '22 21:12

Leander Moesinger