t=0;
dt=0.1;
dd=0.1;
i=0;
while t<=2
t=t+dt;
if t==dd
i=i+1;
dd=dd+0.1;
end
end
fprintf('%f \n',i)
It should print that i is 20, however it prints that it is 0.
I also tried to use rem, but it gives that i is 3
t=0;
dt=0.01;
dd=0.1;
i=0;
while t<=2
t=t+dt;
if rem(t,dd)==0
i=i+1;
dd=dd+0.1;
end
end
fprintf('%f \n',i)
Thanks

 採用された回答

Stephen23
Stephen23 2018 年 5 月 4 日
編集済み: Stephen23 2018 年 5 月 4 日

0 投票

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

タグ

質問済み:

2018 年 5 月 4 日

編集済み:

2018 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by