How to run a loop with isNaN
9 次查看(过去 30 天)
显示 更早的评论
How would i make a loop where if a positive number isnt inputted, The question is asked again?
4 个评论
Davide Masiello
2022-10-17
编辑:Davide Masiello
2022-10-17
Your code seems fine, just remove the line
a =~ NaN;
and it works, meaning that if you input a = nan then it'll display the 'Please only enter a numerical value for a: ' message.
采纳的回答
Davide Masiello
2022-10-17
编辑:Davide Masiello
2022-10-17
disp('Solving a quadratic polynonial (ax^2+bx+c), where a b and c are real numbers to 3 decimal places')
a = input ('What is your value for a?: '); %coefficient of x^2
while ~isnumeric(a) || isnan(a)
a = input ('Please only enter a numerical value for a: ');
end
Solving a quadratic polynonial (ax^2+bx+c), where a b and c are real numbers to 3 decimal places
What is your value for a?: nan
Please only enter a numerical value for a: 'a'
Please only enter a numerical value for a: 2
>>
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!