Creating Matrix with a Dynamic Size

4 Ansichten (letzte 30 Tage)
Gözde Üstün
Gözde Üstün am 1 Jul. 2020
Beantwortet: Gözde Üstün am 1 Jul. 2020
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!

Akzeptierte Antwort

Gözde Üstün
Gözde Üstün am 1 Jul. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by