How can I display only the fprintf without the error shown and using "function"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
function [category] = iqcategory (score)
%by Manav Divekar, 2021-10-28
%if the given score is greater the 130
if score >= 130
fprintf ('Very Superior \n');
elseif score >= 120 && score < 130
fprintf ('Superior \n');
elseif score >= 109 && score < 120
fprintf ('High Average \n');
else
fprintf ('Average \n');
end
>> disp( iqcategory(112.5) )
High Average
error Output argument "category" (and maybe others) not assigned during call to "iqcategory".
0 Kommentare
Antworten (1)
Image Analyst
am 29 Okt. 2021
The error is because you said that your function would return category but you never set a value for it, so it's undefined when it comes time to exit your function. So you either have to set it so something (even null if you want):
function category = iqcategory (score)
category = []; % Initialize to null.
%by Manav Divekar, 2021-10-28
%if the given score is greater the 130
if score >= 130
fprintf ('A score of %.1f is Very Superior.\n', score);
category = 'A score of %.1f is Very Superior';
elseif score >= 120 && score < 130
fprintf ('A score of %.1f is Superior.\n', score);
category = 'Superior';
elseif score >= 109 && score < 120
fprintf ('A score of %.1f is High Average.\n', score);
category = 'High Average';
else
fprintf ('A score of %.1f is Average.\n', score);
category = 'Average';
end
or else just don't bother returning it at all, which means of course you don't set it, or return it, and consequently you won't get the error.
function iqcategory (score)
%by Manav Divekar, 2021-10-28
%if the given score is greater the 130
if score >= 130
fprintf ('A score of %.1f is Very Superior.\n', score);
elseif score >= 120 && score < 130
fprintf ('A score of %.1f is Superior.\n', score);
elseif score >= 109 && score < 120
fprintf ('A score of %.1f is High Average.\n', score);
else
fprintf ('A score of %.1f is Average.\n', score);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!