フィルターのクリア

Why do I get this response 'Operands to the || and && operators must be convertible to logical scalar values.'?

3 ビュー (過去 30 日間)
I wrote this so a user could input a numeric grade and the letter grade would display. I am new to matlab and any help is greatly appreciated.
clear, clc
input('Enter a Grade in Numerical Form?','s');
Grade=ans;
G=Grade;
if G>=90&&G<=100
fprintf('A\n')
end
if G>=80&&G<90
fprintf('B\n')
end
if G>=70&&G<80
fprintf('C\n')
end
if G>=60&&G<70
fprintf('D\n')
end
if G<60
fprintf('F\n')
end
[EDITED, Jan, please format your code - thanks!]

採用された回答

Nirmal
Nirmal 2012 年 7 月 23 日
G=str2num(Grade);
G will be a string so you need to convert that to a number using the str2num function. Its better to use if elseif rather than multiple if statements.
  1 件のコメント
Philip
Philip 2012 年 7 月 23 日
Thanks for the help. I will also change it around if it is better to use if elseif.

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

その他の回答 (1 件)

Jan
Jan 2012 年 7 月 23 日
G = input('Enter a Grade in Numerical Form?');
if G > 100
% do nothing
elseif G>=90
fprintf('A\n')
elseif G>=80
fprintf('B\n')
elseif G>=70
fprintf('C\n')
elseif G>=60
fprintf('D\n')
else
fprintf('F\n')
end

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by