Where is the error in prompt function in this code?
1 次查看(过去 30 天)
显示 更早的评论
for i= 1:4
disp (['enter an angle in degrees']);
x = input(prompt)
y(x) = cos (x);
plot (x,y);
end
y
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!