可能有人知道为什么这个尝试捕获块循环不起作用。我希望只要用户输入一个字符串而不是一个数字,代码就会转到catch块,但它似乎并不想这样做。
x = 1;
while x == 1
try
degree = input('Please enter the degree of the polynomial of interest: ');
if degree > 0 && degree <= 4
x = 0;
else
disp('Please Enter a degree from 1 to 4')
end
catch
exit = input('do you wish to exit (Y/N)','s');
if strcmp(exit,'Y')
break
else
disp('Please enter an integer this time')
end
end
end