How can store the values of this forever-while loop?

1 次查看(过去 30 天)
clear all;clc;
N=1;
SI= exp(-1.*N);
tol = 10.^(-1.*10);
y = zeros(1,24)';
while 1,
SI= exp(-1.*N);
y = SI + rand;
if SI<=tol
break;
end
N=N+1;
end
xk= SI;
k=0:10:50;

回答(1 个)

per isakson
per isakson 2015-11-10
编辑:per isakson 2015-11-10
Try
clear all;clc;
N=1;
SI= exp(-1.*N);
tol = 10.^(-1.*10);
y = zeros(1,0);
while true
SI= exp(-1.*N);
y(1,end+1) = SI + rand;
if SI<=tol
break;
end
N=N+1;
end
xk= SI;
k=0:10:50;
y
it outputs
y =
Columns 1 through 9
1.1822 0.3789 0.9791 0.3683 0.2033 0.2536 0.6170 0.4736
.....

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by