1 view (last 30 days)

Hello,

I am trying to create block diagonal if dimension d is greater than 2. However I have this error:

Unable to perform assignment because the size of the left side is 4-by-4 and the size of the right side is 2-by-4.

My code is here:

function [A,B] = CH2d(d)

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

for l =1:d

if d > 2

A(:,:,1,k) = blkdiag(A(:,:,1,k));

end

A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),1,d);

end

end

end

Opportunities for recent engineering grads.

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915460

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915460

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915478

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915478

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915511

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915511

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915604

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/555475-unable-to-perform-assignment-because-the-size-of-the-left-side-is-4-by-4-and-the-size-of-the-right-s#comment_915604

Sign in to comment.