Define a matrix in terms of kronecker product

1 view (last 30 days)
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.

Accepted Answer

Matt J
Matt J on 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 Comments
Shilpi Mishra
Shilpi Mishra on 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 on 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

Sign in to comment.

More Answers (2)

dpb
dpb on 13 Jun 2021
Edited: dpb on 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 Comment
Shilpi Mishra
Shilpi Mishra on 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.

Sign in to comment.


Matt J
Matt J on 13 Jun 2021
Edited: Matt J on 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

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!