Where is the error in prompt function in this code?

1 回表示 (過去 30 日間)
Batool Khader
Batool Khader 2019 年 4 月 5 日
回答済み: Walter Roberson 2019 年 4 月 5 日
for i= 1:4
disp (['enter an angle in degrees']);
x = input(prompt)
y(x) = cos (x);
plot (x,y);
end
y

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 5 日
prompt is not a defined variable. Perhaps you should have used
prompt = 'enter an angle in degrees: ';
Note that your prompt talks about degrees, but cos() works in radians. cosd() works in degrees.
Your code would work (not crash) if the user happened to enter a positive integer, but what if the user happened to enter 0 or negative? y(x) when x is 0 would be a problem.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by