How to write a program in Matlab which takes as input a student’s grade (such as ‘81’) and return a new grade in the A,B,C etc scale?

Here is the scale: A-=90-92 B+=87-89 B=83-86 B-=80-82 C+=77-79 C=73-76 C-=70-72 D+=67-69 D=64-66 F=0-63

3 comentarios

What have you tried? Or did you just come straight here as soon as you got the question?
You should replace
grad = input('Grad>')
with
grad = input('Please enter a numerical grad >')
and then do so when running the program. You tried to call clear when your are expected to provide the grad number as input.

Iniciar sesión para comentar.

Respuestas (2)

grad = input('Grad> ')
if grad >= 90
newgrad = 'A-';
elseif grad >= 87
newgrad = 'B+';
elseif ...
or write a function
function newgrad = getgrad(grad)
if grad >= 90...
Or fully vectorized using histc:
>> inp = [95,16,85,50,75]; % example values
>> V = [-Inf,64, 67, 70, 73, 77, 80, 83, 87,90,Inf];
>> C = {'F','D','D+','C-','C','C+','B-','B','B+','A-'};
>> [~,X] = histc(inp,V);
>> out = C(X);
>> out{:}
ans = A-
ans = F
ans = B
ans = F
ans = C

Categorías

Más información sobre Instrument Control Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 4 de Nov. de 2015

Editada:

el 4 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by