excel and matlab problem

2 ビュー (過去 30 日間)
Jay vee
Jay vee 2022 年 7 月 20 日
コメント済み: Voss 2022 年 7 月 20 日
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

採用された回答

Voss
Voss 2022 年 7 月 20 日
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 件のコメント
Jay vee
Jay vee 2022 年 7 月 20 日
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 2022 年 7 月 20 日
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'}

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by