excel and matlab problem

2 views (last 30 days)
Jay vee
Jay vee on 20 Jul 2022
Commented: Voss on 20 Jul 2022
I have this set of data and i want to grade the average grades and output each students result with the grade. Currently the code still does not assign the grades with the averages. Kindly assist
T = readtable('C:\Users\RONNIE\Documents\EXCEL.xlsx');
NAMES = T.(1) ;
format short
AvgMarks = mean(table2array(T(:,2:end)),2) ;
if (70<=AvgMarks)&(AvgMarks<=100)
fprintf ('A')
elseif (60<=AvgMarks)&(AvgMarks<=69)
fprintf ('B')
elseif (50<=AvgMarks)&(AvgMarks<=59)
fprintf ('C')
elseif (40<=AvgMarks)&(AvgMarks<=49)
fprintf ('D')
else
fprintf ('E')
end
Tavg = table(NAMES,AvgMarks)
STUDENTRESULTS=T(1,1:end)
format short

Accepted Answer

Voss
Voss on 20 Jul 2022
T = readtable('EXCEL.xlsx');
NAMES = T.(1) ;
AvgMarks = mean(table2array(T(:,2:end)),2) ;
Grades = cell(size(T,1),1);
Grades(AvgMarks >= 70) = {'A'};
Grades(AvgMarks >= 60 & AvgMarks < 70) = {'B'};
Grades(AvgMarks >= 50 & AvgMarks < 60) = {'C'};
Grades(AvgMarks >= 40 & AvgMarks < 50) = {'D'};
Grades(AvgMarks < 40) = {'E'};
Tavg = table(NAMES,AvgMarks,Grades)
Tavg = 80×3 table
NAMES AvgMarks Grades _______________________ ________ ______ {'Mandy Vance' } 48.667 {'D'} {'Jermaine Mcmillan' } 37.333 {'E'} {'Kristy Levy' } 45 {'D'} {'Rudy Mcneil' } 53.167 {'C'} {'Octavio Wheeler' } 50.667 {'C'} {'Raquel Bass' } 51.5 {'C'} {'Blake Colon' } 57.667 {'C'} {'Rosetta Olsen' } 85.5 {'A'} {'Esperanza Ross' } 49.5 {'D'} {'Mable Strickland' } 58.833 {'C'} {'Tameka Cameron' } 37.5 {'E'} {'Marcelino Rasmussen'} 43.167 {'D'} {'Pierre Galloway' } 40.333 {'D'} {'Jake Chung' } 51.5 {'C'} {'Jorge Oliver' } 47.333 {'D'} {'Tracie Alvarez' } 59.167 {'C'}
  2 Comments
Jay vee
Jay vee on 20 Jul 2022
The grading did work, but from my code above i was trying to output the results for single students, like a program that gives back the results for single student and displays it. This one displayed the results for all the students
Voss
Voss on 20 Jul 2022
T = readtable('EXCEL.xlsx');
NAMES = T.(1) ;
AvgMarks = mean(table2array(T(:,2:end)),2) ;
Grades = cell(size(T,1),1);
Grades(AvgMarks >= 70) = {'A'};
Grades(AvgMarks >= 60 & AvgMarks < 70) = {'B'};
Grades(AvgMarks >= 50 & AvgMarks < 60) = {'C'};
Grades(AvgMarks >= 40 & AvgMarks < 50) = {'D'};
Grades(AvgMarks < 40) = {'E'};
Tavg = table(NAMES,AvgMarks,Grades);
student_name = 'Raquel Bass'
student_name = 'Raquel Bass'
student_grade = Tavg{strcmp(Tavg.NAMES,student_name),'Grades'}
student_grade = 1×1 cell array
{'C'}

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!