フィルターのクリア

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 Center および File ExchangeLoops 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