How Can I create a function as a string
Afficher commentaires plus anciens
Hı guys
Write a program that enters students' grades and gives them in the command window the mark they deserve (from A to F) with some comments. (write it as a function and M-file script )
How Can I do that?
function grade=input('Write the grade:';'s');
if grade=='A'||'a'
disp('excellent')
elseif grade=='B'||'b'
disp('well done')
elseif grade=='C'||'c'
disp('Great')
elseif grade=='D'||'d'
disp('better try again')
elseif grade=='F'||'f'
disp('Invalid grade')
else
end
end
I wrote this function but I have to ask to user the grades like A-B-C etc.
So how can ı write the input in the m-file
1 commentaire
"How Can I do that?"
Search for "greater than" and "less than".
Réponses (1)
Sean de Wolski
le 16 Déc 2021
Modifié(e) : Sean de Wolski
le 16 Déc 2021
function grade=mygrade(grade)
arguments
grade(1,1) string = input('Write the grade:';'s')
end
grade = lower(grade);
if grade == 'a'
disp('excellent')
elseif grade == 'b'
disp('well done')
elseif grade == 'c'
disp('Great')
elseif grade == 'd'
disp('better try again')
elseif grade == 'f'
disp('Invalid grade')
else
end
end
1 commentaire
Talha Tetik
le 16 Déc 2021
Catégories
En savoir plus sur Language Fundamentals dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!