Creating a MatLab code to convert numerical grades into letter grades.

조회 수: 12 (최근 30일)
Robert Windham
Robert Windham 2019년 9월 21일
댓글: Robert Windham 2019년 9월 22일
Hey all!
I've currently working on creating a code that will allow me to convert numbers into a letter grade that can be put into a single column vector (1X25) and I can't figure out how to make it work. I thought I may have been onto something with this:
lg=mn; %lg is just what I'm calling letter grade and mn in the mean grade of the students assignments (also a 1X25).
if 90<=mn<=100
disp('A')
elseif 80<=mn<=89
disp('B')
elseif 60<=mn<=79
disp('C')
elseif 40<=mn<=59
disp('D')
elseif mn<40
disp('F')
end
I don't recieve any errors when I run it but it also doesn't provide me with any letter grades.
Any help would be greatly appreciated!
V/R,
Bobby
  댓글 수: 2
David Hill
David Hill 2019년 9월 21일
x(x>=60&x<70)='D';
x(x>=90)='A';
x(x>=80)='B';
x(x>=70)='C';
x(x<60)='F';
x=char(x);
This provides a char array
Robert Windham
Robert Windham 2019년 9월 22일
I tried doing this with a character array but because I want to include the 25X1 into another huge matrix, it messes up the rest of the matrix (looks like wingdings when I run the code).
Thank you, though!

댓글을 달려면 로그인하십시오.

답변 (1개)

madhan ravi
madhan ravi 2019년 9월 21일
편집: madhan ravi 2019년 9월 21일
You should loop through mn and save the results as a cell array in a variable which is preallocated before loop using indexing. Or better just use logical indexing and store the results as a cell array.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by