Creating Dynamic High Dimensional Block Diagonal Matrix

Hello,
I can create a matrix for dimenson = 2. However for even d and d>2, It should be a lock diagonal matrix of the previous result. I cannot run my code. I tried too many combination but I dont know how I can solve my problem
Here is my code:
A=zeros(d,d,2,d);
B=A;
projectors_of_sigma_x = [1/sqrt(2)*[1;1],1/sqrt(2)*[1;-1]];
for k = 1:d
A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),1,d); % In this line I am giving the value (1/sqrt(2)*[1;1]) to A(:,:,1,1) and value 1/sqrt(2)*[1;-1] to A(:,:,1,2)
if k > 2
A(:,:,1,k) = repmat({A(:,:,1,k)}, 1, d/2); %This line and the following line I am trying to create a matrix which is a blog diagonal of the previous result for even d and of course d>2
A(:,:,1,k) = blkdiag(A{:,:,1,k});
end
end

답변 (0개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 6월 27일

편집:

2020년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by