Azzera filtri
Azzera filtri

Creating Matrix with a Dynamic Size

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

Gözde Üstün
Gözde Üstün il 1 Lug 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by