using fprintf within a function
显示 更早的评论
The function goes like this. How do I enter an fprintf statement so that the output looks like this:
>>num2let(83)
>>The corresponding letter grade to 83 is:B
function [grade]= num2let(n)
If n>89.49
grade='A'
elseif n<=89.49 & n=>79.5
grade='B'
......
...
elseif n<59.5 grade='F'
end
end
1 个评论
Walter Roberson
2013-2-18
You have defined this as a function that returns a value. What do you want returned? The verbose string? Just the letter grade?
Remember, functions that return values cause the returned value to be printed out in the form
ans =
unless something is done with the returned value, or the display is suppressed by putting a semi-colon after the expression.
采纳的回答
更多回答(1 个)
Thorsten
2013-2-18
If you do not insist on fprintf, you can get the output using
grade = 83;
disp(['The corresponding letter grade to ' int2str(grade) ' is ' ...
num2let(grade)])
类别
在 帮助中心 和 File Exchange 中查找有关 Language Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!