How can store the values of this forever-while loop?
Ältere Kommentare anzeigen
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;
Antworten (1)
per isakson
am 10 Nov. 2015
Bearbeitet: per isakson
am 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
.....
1 Kommentar
Ruten9
am 10 Nov. 2015
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!