필터 지우기
필터 지우기

Define a matrix in terms of kronecker product

조회 수: 2 (최근 30일)
Shilpi Mishra
Shilpi Mishra 2021년 6월 13일
댓글: Matt J 2021년 6월 15일
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