Cartesian product of 2 matrices

9 vues (au cours des 30 derniers jours)
Regita Agustin Wahyu F
Regita Agustin Wahyu F le 8 Juin 2022
Commenté : Jesús G. le 9 Oct 2023
Let A and B are sets of 16 matrices size 2x2, say A = {M1,M2,M3,...,M16}, B = {M1,M2,M3,...,M16}, with entry each Mi, i = 1,..,16 are 0 and 1, eg : M1=[0 0; 0 0], M2 = [0 1; 0 0],...,M16 = [1 1; 1 1]. How the syntax of those cartesian product of A and B ? Later the result AxB = {(M1,M1), (M1,M2),...,(M16,M16)} with total elements of AxB are 256 paired orders.
  1 commentaire
Jesús G.
Jesús G. le 9 Oct 2023
May i ask what was the motivation for this problem. I what type of problem did you find such cartesian product of matrices

Connectez-vous pour commenter.

Réponses (1)

Torsten
Torsten le 8 Juin 2022
Modifié(e) : Torsten le 8 Juin 2022
m = 4;
justRows = dec2bin(0:2^m-1)-'0';
n = size(justRows,1);
M = cell(2^m,1);
for i = 1:n
A = reshape(justRows(i,:),[sqrt(m),sqrt(m)]);
M{i} = A;
end
McrossM = cell(n,n);
for i=1:n
for j=1:n
McrossM{i,j} = {M{i},M{j}};
%disp(McrossM{i,j})
end
end
  2 commentaires
Regita Agustin Wahyu F
Regita Agustin Wahyu F le 8 Juin 2022
thankyou sir for the answer, but i mean for this case how to make tuple (M{i},M{j}) not M{i}*M{j}, then the result is a set of tuples like
A={1 2 3} and B = {a b} then AxB = {(1,a),(2,a),(3,a),(1,b),(2,b),(3,b)};
sign 'cross' means cartesian product not 'multiply' like 2x3=6.
Torsten
Torsten le 8 Juin 2022
I changed the code accordingly.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by