Define a matrix in terms of kronecker product

2 次查看(过去 30 天)
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.

采纳的回答

Matt J
Matt J 2021-6-13
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 个评论
Shilpi Mishra
Shilpi Mishra 2021-6-14
Thank you, it worked. Can the last step C=C(p,:) be done using some matrix operation like matrix multiplication?
Matt J
Matt J 2021-6-15
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

请先登录,再进行评论。

更多回答(2 个)

dpb
dpb 2021-6-13
编辑:dpb 2021-6-13
>> 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 个评论
Shilpi Mishra
Shilpi Mishra 2021-6-13
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.

请先登录,再进行评论。


Matt J
Matt J 2021-6-13
编辑:Matt J 2021-6-13
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

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by