How do I write a number and Letter in the same line?

2 ビュー (過去 30 日間)
Elijah McNeil
Elijah McNeil 2020 年 10 月 28 日
コメント済み: Elijah McNeil 2020 年 10 月 28 日
values = {'Enter a value that is equal to or greater than 0 but equal to or less than 100:','Enter a 2nd value that is equal to or greater than 0 but equal to or less than 100:'};
values = inputdlg(values)
values = str2double(values)
n = mean(values)
if n >= 91
grade='A'
elseif n >= 81
grade='B'
elseif n >= 71
grade='C'
elseif n >= 61
grade='D'
else
grade='F'
end
k = n + grade
disp(k)
I need to write n and grade on the same line, but when this runs, instead of displaying the value of n, it displays a seemingly random symbol or number with the grade letter attached.
example: If I enter 88 & 67 it makes k = 'MC', the values 100 & 20 make k = '<F'.
Please help.

採用された回答

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 10 月 28 日
You can use:
fprintf('grade=%f, %s\n',n, grade);
  1 件のコメント
Elijah McNeil
Elijah McNeil 2020 年 10 月 28 日
That worked! Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by