필터 지우기
필터 지우기

Creating Matrix with a Dynamic Size

조회 수: 1 (최근 30일)
Gözde Üstün
Gözde Üstün 2020년 7월 1일
답변: Gözde Üstün 2020년 7월 1일
Hello,
I can create 2*2 matrix with the following code but for higher dimension I can not:
function [A,B] = CHSH2d(d)
A=zeros(d,d,2,d);
B=A;
projectors_of_sigma_x = [1/sqrt(2)*[1;1],1/sqrt(2)*[1;-1]];
if d==2
A(:,:,1,k) = projectors_of_sigma_x(:,k)*transpose(projectors_of_sigma_x(:,k));
A(:,:,2,k) = projectors_of_sigma_z(:,k)*transpose(projectors_of_sigma_z(:,k));
else
A(:,:,1,1)=repmat(projectors_of_sigma_x(1)*transpose(projectors_of_sigma_x(1)),d,d); %this line is ok
A(:,:,1,2)=repmat(projectors_of_sigma_x(2)*transpose(projectors_of_sigma_x(2)),d,d); %In this line I am seeing the same result with A(:,:,1,1)
end
end
In the result of A(:,:,1,2) I am seeing the same result with A(:,:,1,1) but I should not!

채택된 답변

Gözde Üstün
Gözde Üstün 2020년 7월 1일
Ok I solved the problem:
for l=1:2
A(:,:,1,k) = repmat(projectors_of_sigma_x(:,l)*transpose(projectors_of_sigma_x(:,l)),d/2,d/2);
A(:,:,2,k) = repmat(projectors_of_sigma_z(:,l)*transpose(projectors_of_sigma_z(:,l)),d/2,d/2);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by