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!