MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

How to convert grade into letter grade

Jiawei Weng さんによって質問されました 2019 年 1 月 20 日
最新アクティビティ Jiawei Weng さんによって コメントされました 2019 年 1 月 21 日
Hi guys, wonder how to transfer grade into letter grade. I have already calculated the code, which is following:
NA = 4;
PS = [75, 62, 80, 71, 0, 32, 56, 80];
PR = 68;
EM = 78;
n=2;
u=unique(PS)
if numel(u)==1 || numel(u)==2
Result=[]
else
Result=mean(PS(~ismember(PS,u(1:n))))
end
a = Result
if NA <= 2
b = 15
end
if NA == 3
b = 14
end
if NA == 4
b = 13
end
if NA == 5
b = 12
end
if NA == 6
b = 11
end
if NA == 7
b = 10
end
if NA == 8
b = 9
end
if NA == 9
b = 8
end
if NA == 10
b = 7
end
if NA == 11
b = 6
end
if NA == 12
b = 5
end
c = PR*0.3
d = EM*0.2
e = a*0.35
grade = b + c + d + e
NA = 1;
PS = [90, 100, 100, 84, 89, 92, 73];
PR = 96;
EM = 0;
n=2; % two smallest values
u=unique(PS)
if numel(u)==1 || numel(u)==2
Result=[]
else
Result=mean(PS(~ismember(PS,u(1:n))))
end
a = Result
if NA <= 2
b = 15
end
if NA == 3
b = 14
end
if NA == 4
b = 13
end
if NA == 5
b = 12
end
if NA == 6
b = 11
end
if NA == 7
b = 10
end
if NA == 8
b = 9
end
if NA == 9
b = 8
end
if NA == 10
b = 7
end
if NA == 11
b = 6
end
if NA == 12
b = 5
end
c = PR*0.3
d = EM*0.2
e = a*0.35
grade = b + c + d + e
I know I am super unskilled lol. Anyway, at first I tried
function grade=letter_grade
if grade >= 91
letter_grade='A';
elseif n >= 81
letter_grade='B';
elseif n >= 71
letter_grade='C';
elseif n >= 61
letter_grade='D';
else
letter_grade='F';
end
end
but it doesn't work. Please help me with that, thanks in advance.
PS: 90-100 A+
80-89 A
70- 79 B
60-69 C
50-59 D
below 50 F

  0 件のコメント

サインイン to comment.

タグ

製品


リリース

R2018b

1 件の回答

回答者: per isakson
2019 年 1 月 20 日
編集済み: per isakson
2019 年 1 月 21 日
 採用された回答

I guess this is what you intended
function grade = letter_grade( n )
if n >= 91
grade='A';
elseif n >= 81
grade='B';
elseif n >= 71
grade='C';
elseif n >= 61
grade='D';
else
grade='F';
end
end
and test the function
>> letter_grade( 75 )
which returns "C"
However, note that this function will not give results according to
PS: 90-100 A+
80-89 A
70- 79 B
60-69 C
50-59 D
below 50 F
but it runs without errors.

  5 件のコメント

Jiawei Weng 2019 年 1 月 21 日
It is pretty weird that I put it in Command window, but it shows " Undefined function or variable 'letter_grade'." But I believe I have defined that, what am I doing wrong. Do I need to set any thing before I typr letter_grade?
per isakson
2019 年 1 月 21 日
IMO: It is not possible to effectively use Matlab without constantly consulting the documentation. See Create Functions in Files.
"Do I need to set any thing before I typr letter_grade?" YES
  1. Create a file named, letter_grade.m, that contains the code of the function
  2. Save that file in a folder that is in the Matlab search path, i.e. see Search Path
Jiawei Weng 2019 年 1 月 21 日
Great! it works perfectly, thank you so much sir.

サインイン to comment.



Translated by