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

2 views (last 30 days)
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;

Answers (1)

per isakson
per isakson on 10 Nov 2015
Edited: per isakson on 10 Nov 2015
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
.....

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!