Cartesian product of 2 matrices

4 Ansichten (letzte 30 Tage)
Regita Agustin Wahyu F
Regita Agustin Wahyu F am 8 Jun. 2022
Kommentiert: Jesús G. am 9 Okt. 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 Kommentar
Jesús G.
Jesús G. am 9 Okt. 2023
May i ask what was the motivation for this problem. I what type of problem did you find such cartesian product of matrices

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Torsten
Torsten am 8 Jun. 2022
Bearbeitet: Torsten am 8 Jun. 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 Kommentare
Regita Agustin Wahyu F
Regita Agustin Wahyu F am 8 Jun. 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 am 8 Jun. 2022
I changed the code accordingly.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by