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

1 回表示 (過去 30 日間)
Ruten9
Ruten9 2015 年 11 月 10 日
編集済み: per isakson 2015 年 11 月 10 日
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
.....
  1 件のコメント
Ruten9
Ruten9 2015 年 11 月 10 日
It worked! Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by