フィルターのクリア

How to run a loop with isNaN

3 ビュー (過去 30 日間)
Benjamin
Benjamin 2022 年 10 月 17 日
コメント済み: Benjamin 2022 年 10 月 18 日
How would i make a loop where if a positive number isnt inputted, The question is asked again?
  4 件のコメント
Davide Masiello
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.
Benjamin
Benjamin 2022 年 10 月 17 日
@Davide Masiello is there a way for this code to work if any letter is inputted as my value of a

サインインしてコメントする。

採用された回答

Davide Masiello
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
>>
  1 件のコメント
Benjamin
Benjamin 2022 年 10 月 18 日
thankyou

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by