how can i store a value of a calculation in a loop
조회 수: 2(최근 30일)
표시 이전 댓글
Hi I have the following loop.
for k=1:length(hplid)
x=hplid(k);
q=sort(latency(hpl==x));
size(q);
figure;
plot(q,(1:numel(q))/numel(q))
title(['HPL ', num2str(x), ' Latency']);
xlabel('Seconds');
ylabel('% Percentile');
quant=interp1((1:numel(q))/numel(q),q,[.9 .95 .99]);
disp( '90%, 95% and 99% latency');
disp(quant);
end
how can I store the value of quants to an array everytime the loop is exectued. Right quants only store the calculation of the last iteration of the loop.
Thank you
답변(2개)
Jan
2017년 10월 5일
편집: Jan
2017년 10월 5일
Store the vectors in a matrix using the loop counter as index:
quant = zeros(length(hplid), 3); % Pre-allocate!!!
for k = 1:length(hplid)
...
quant(k, :) = interp1((1:numel(q))/numel(q),q,[.9 .95 .99]);
disp(quant(k, :));
end
Note: The line "size(q);" is useless.
댓글 수: 2
Jan
2017년 10월 6일
@Ketan: Please post the complete error message and the relevant part of the code. I can neither guess, which line causes the error, nor which variable has the type "duration". Note that the message contains a hint about the solution already.
jean claude
2017년 10월 5일
try this put it just before end of the loop
quantvalue=[];
quantvalue=[quantvalue quant];
댓글 수: 2
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!