Write a function that accepts an input vector of integer exam scores and outputs
ID: 3815071 • Letter: W
Question
Write a function that accepts an input vector of integer exam scores and outputs a two column cell array with the same number of rows as the input vector. Each cell in the first column should contain a score from the input vector. The cells in the second column should have strips that give the corresponding letter grade according to the following grading scale. Score values ranging from 90 to 100 receive an A. Score ranging from 80 to 89 receive a B. Score values ranging from to 79 receive a C. Score values ranging from 60 to 69 receive a 0. Score values ranging from 0 to 59 receive an F. tRNC #CHAR, #CELLExplanation / Answer
Function:
function [ result ] = score( input )
result=[];
for i=1:size(input)
if(input(i)>=90)
result=[result; num2str(input(i)),' A'];
elseif(input(i)>=80)
result=[result; num2str(input(i)),' B'];
elseif(input(i)>=70)
result=[result; num2str(input(i)),' C'];
elseif(input(i)>=60)
result=[result; num2str(input(i)),' D'];
else
result=[result; num2str(input(i)),' F'];
end
end
end
Result:
>> score(input)
ans =
10 F
45 F
98 A
78 C
36 F
25 F
86 B
74 C
35 F
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.