フィルターのクリア

How to make a loop until the same result is obtained

2 ビュー (過去 30 日間)
Emilia
Emilia 2020 年 11 月 30 日
コメント済み: Emilia 2020 年 11 月 30 日
Hello,
I need help how to be used correctly in the loop, I have here a parameter table.
Example: I have k that place in the equation so i get d=23.83 and cheak if that no same ,continue until is same Out=d.
Thanks for the helpers
for k=[2.73 2.56 2.47 2.42 2.39]
d=130-(K*(350/9));
if d/130==[0.1 0.18 0.23 0.26 0.28]
Out=d
end
end
  8 件のコメント
Rik
Rik 2020 年 11 月 30 日
So essentially you want to round to 2 decimals? Or do you have a variable number of digits you want to round to? And do you actually want to round the values, or just display them with 2 digits?
Emilia
Emilia 2020 年 11 月 30 日
yes to round the values so
ans = 0.1833=0.18 compare to 0.1
ans = 0.2342=0.23 compare to 0.18
ans = 0.2611=0.26 compare to 0.23
ans = 0.2761=0.27 compare to 0.26
ans = 0.2850=0.28 compare to 0.28 => same number => Out=d=37.06

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

採用された回答

Doris Brand
Doris Brand 2020 年 11 月 30 日
Would that do it?
Out = 0;
for k=[2.73 2.56 2.47 2.42 2.39]
d=round((130-(k*350/9))/130,2);
if ismember(d, [0.1 0.18 0.23 0.26 0.28])
Out=d;
end
end
fprintf('Out=d=%3.2f\n',Out)

その他の回答 (0 件)

カテゴリ

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