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

조회 수: 2 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by