How can I save the elements into a List with a For Loop

5 ビュー (過去 30 日間)
Gözde Üstün
Gözde Üstün 2020 年 7 月 8 日
回答済み: madhan ravi 2020 年 7 月 8 日
Hey,
I am trying to my results in a for loop but I can save just the last result How can I solve the problem?
function[ rho,gs,hs,k_value ]= plott(a,b)
numbers = [0.9,0.95,0.96,0.97,0.98,0.99,0.9977,0.9978,0.9979,0.998,0.999,1];
d = 2;
k_value=[];
rhos=[];
gs=[];
hs=[];
for i=length(numbers)
a=noise(i);
rho = dep(d,noise(i));
P=Pr(alice,bob,rho);
[G,B,rho]=T(P,a,b);
H=H_(P(:,:,1,1))
K=-log2(G)-H;
k_value(i)=[K];
hs(i)=[H];
gs(i)=[G];
rhos=[rho];
end
% k_value=[K];
% hs=[H];
% gs=[G];
% rhos=[rho];
end

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 8 日
function[ rho,gs,hs,k_value ]= plott(a,b)
numbers = [0.9,0.95,0.96,0.97,0.98,0.99,0.9977,0.9978,0.9979,0.998,0.999,1];
d = 2;
[k_value,rhos,gs,hs] = deal(zeros(numel(numbers),1));
for ii = 1 : numel(numbers)
a=noise(ii);
rho = dep(d,noise(ii));
P=Pr(alice,bob,rho);
[G,B,rho]=T(P,alice,bob);
H=H_(P(:,:,1,1))
K=-log2(G)-H;
k_value(ii)= K;
hs(ii)= H;
gs(ii)= G;
rhos(ii) =rho;
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by