Filter löschen
Filter löschen

Define a matrix in terms of kronecker product

2 Ansichten (letzte 30 Tage)
Shilpi Mishra
Shilpi Mishra am 13 Jun. 2021
Kommentiert: Matt J am 15 Jun. 2021
I want to represent the (n^2)x(n^3) binary matrix below in terms of kron(A,B), where A and B are defined in terms of n. In the example shown, n=3. The vacant entries are 0 and the 1s occur in shown pattern.

Akzeptierte Antwort

Matt J
Matt J am 13 Jun. 2021
n=3;
e=ones(1,n);
A=eye(n);
B=kron(e,A);
p=reshape(1:n^2,n,[]).';
C=kron(A,B);
C=C(p,:)
C = 9×27
1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1
  2 Kommentare
Shilpi Mishra
Shilpi Mishra am 14 Jun. 2021
Thank you, it worked. Can the last step C=C(p,:) be done using some matrix operation like matrix multiplication?
Matt J
Matt J am 15 Jun. 2021
Yes.
n=3;
e=ones(1,n);
A=eye(n);
B=kron(e,A);
p=reshape(1:n^2,n,[]).';
P=eye(n^2); P=P(p,:);
C=P*kron(A,B)
C = 9×27
1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

dpb
dpb am 13 Jun. 2021
Bearbeitet: dpb am 13 Jun. 2021
>> I=3;N=4;
>> kron(ones(1,N),eye(I))
ans =
1 0 0 1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1
>>
  1 Kommentar
Shilpi Mishra
Shilpi Mishra am 13 Jun. 2021
Thanks for your reply, but the pattern needed is different. Each row has got three 1s appearing in a pattern overall as shown. The size of the matrix in the example is 9x27.

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 13 Jun. 2021
Bearbeitet: Matt J am 13 Jun. 2021
n=3;
I=eye(n);
e=ones(1,n);
z=zeros(1,n);
C=cell(n,1);
for i=1:n
q=z;
q(i)=1;
C{i}=kron(kron(I,e),q);
end
C=cell2mat(C)
C = 9×27
1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1

Kategorien

Mehr zu Colormaps 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