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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

madhan ravi
madhan ravi am 8 Jul. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by