How can store the values of this forever-while loop?
Afficher commentaires plus anciens
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;
Réponses (1)
per isakson
le 10 Nov 2015
Modifié(e) : per isakson
le 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 commentaire
Ruten9
le 10 Nov 2015
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!