How permutate 2-by-2 matrices in a single matrix
Mostra commenti meno recenti
Hello everyone
I have three
matrices as:
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
Risposta accettata
Più risposte (1)
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 Commenti
Peiman Khandar
il 29 Ott 2022
Rik
il 29 Ott 2022
What do you mean by that operation? What is abc(1,1)?
Peiman Khandar
il 29 Ott 2022
Bruno Luong
il 29 Ott 2022
Modificato: Bruno Luong
il 29 Ott 2022
"I mean 2 times the first row and first column of overall matrix [abc] where it contains a matrix"
Then litterally it is 2*abc(1,1), that means 2*3 = 6
but I guess this is NOT what you want. Describtion verbally and innacurately is the last thing you would do to ask question.
Peiman Khandar
il 29 Ott 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}
Peiman Khandar
il 29 Ott 2022
Modificato: Peiman Khandar
il 29 Ott 2022
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!