How to create combinations of rows in an array?

2 views (last 30 days)
Hi all,
Here is my problem:
I have an array:
data=[15 6;85 54;90 4;56 87;37 15;24 65]
% my input
I want to obtain the result that show combinations of rows for the above array, which would be:
15 6 15 6 15 6
85 54 85 54 85 54
90 4 90 4 90 4
56 87 56 87 24 65
37 15 24 65 56 87
24 65 37 15 37 15
And goes on until every row is in all available positions.
I am looking forward to your helps. Thanks a lot!
  1 Comment
Rik
Rik on 9 Dec 2020
Comment posted as flag by Anh Nguyen:
I have found another answer that gives a more clear output and suits my needs.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Dec 2020
result = permute(reshape( data(perms(1:size(data,1)).',:).', size(data,2), size(data,1), []), [2 1 3]);

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!