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 Kommentare

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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Thorsten
Thorsten am 4 Nov. 2015
Bearbeitet: Thorsten am 4 Nov. 2015
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...
Stephen23
Stephen23 am 4 Nov. 2015
Bearbeitet: Stephen23 am 4 Nov. 2015
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

Kategorien

Mehr zu Instrument Control Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Nov. 2015

Bearbeitet:

am 4 Nov. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by