How permutate 2-by-2 matrices in a single matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Peiman Khandar
am 28 Okt. 2022
Bearbeitet: Peiman Khandar
am 29 Okt. 2022
Hello everyone
I have three
matrices as:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1172308/image.png)
a = [1,2;3,4]; b = [2,5;1,6]; c = [3,7;2,4];
and collect them in a single M matrix as, M = [a,b,c]. Now I want to have permutation of these three matrices in M_P matrix as:
M_P = [a b c;
a c b;
b a c;
b c a;
c a b;
c b a].
When I use M_P = perms(M), I could not obtain the [M_P] written above. it permutation all the value inside the matirices, however I just want permutation just matrices (a,b,c) then, place the values of matrices. I would appriciate it you can help me
Thanks in advance
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 28 Okt. 2022
a = [1,2;3,4]; b = [2,5;1,6]; c = [3,7;2,4];
abc= {a,b,c};
abc=perms(abc)
abc=cell2mat(abc)
3 Kommentare
Bruno Luong
am 29 Okt. 2022
Take a look at cellfun
It's funny that you ask to create data in format that you don't know how to work with. It is better that you don't jump quickly and think more about the data structure that you know how to manipulate downstream.
Might be what you need is 4D array and not a 2D array of all permulations clump together.
Weitere Antworten (1)
Rik
am 28 Okt. 2022
Bearbeitet: Rik
am 28 Okt. 2022
You're close. You just need to store a, b, and c in a cell array and use perms to create indices.
The benefit of this approach is that you can extend it to more or fewer elements (although you will run into memory constraints fast with a larger number of matrices).
a = [1,2;3,4]; b = [2,5;1,6]; c = [3,7;2,4];
collation = {a,b,c};
inds = perms(1:numel(collation))
M_P = collation(inds)
M_P = cell2mat(M_P)
7 Kommentare
Bruno Luong
am 29 Okt. 2022
a = [1,2;3,4]; b = [2,5;1,6]; c = [3,7;2,4];
abc= {a,b,c};
abc=perms(abc);
2*abc{1,1}
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!