Grading system in excel sheet based on marks

4 ビュー (過去 30 日間)
busy girl
busy girl 2021 年 1 月 7 日
コメント済み: Bushra ashiq 2021 年 1 月 15 日
I am tyring to paste grade on excel sheet based on marks
i do this but this shows only F in excel sheet .. i want if anybody has marks >=80 then want to show A grade .. and if anybody hay >=70 then B
and if anybody hay less than 70 then want to show F
clc;clear all
filename = 'PROJECT..xlsx';
table = readtable(filename);
data = xlsread(filename);
[r,c] = size(data);
total_courses = c;
table.SumofMarks = zeros(r,1);
table.Percentage = zeros(r,1);
table.StudentGrade = repmat({''},r,1);
% Sum of marks in different courses and their percentage.
format bank
Sum_of_Marks = sum(data,2);
Student_Percentage = Sum_of_Marks./c;
T = horzcat(Sum_of_Marks,Student_Percentage);
N = length(Student_Percentage);
R = reshape(Student_Percentage,1,[]); % convert matrix to row vector
for i = 1:1:N
if R>=80
table.StudentGrade{i} = 'A';
elseif R>=70
table.StudentGrade{i} = 'B';
elseif R <70
table.StudentGrade{i}= 'F';
end
end
writetable(table,filename)
xlswrite(filename,T,1,'H2')
i tried this but this code doesnt work
how i do this
i attached excel file
please help
  3 件のコメント
busy girl
busy girl 2021 年 1 月 7 日
@Image Analyst.. i update question and attach PROJECT.XLsx file.. please check
busy girl
busy girl 2021 年 1 月 8 日
any help plzzzzzzz

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

回答 (1 件)

Alan Stevens
Alan Stevens 2021 年 1 月 8 日
Shouldn't you have
for i = 1:1:N
if R(i)>=80
table.StudentGrade{i} = 'A';
elseif R(i)>=70
table.StudentGrade{i} = 'B';
elseif R(i) <70
table.StudentGrade{i}= 'F';
end
end
  11 件のコメント
Alan Stevens
Alan Stevens 2021 年 1 月 15 日
Come to think of it, that line should probably be
elseif R(i) <70 || ismember(i,fails)
Bushra ashiq
Bushra ashiq 2021 年 1 月 15 日
hi.. i tried your code and add conditions like these just replace numbers 70 to 40.. but this paste according to total marks where as i want if there is less than 40 marks in any subject then want to paste F grade ..
filename = 'PROJECT..xlsx';
table = readtable(filename);
data = xlsread(filename);
[r,c] = size(data);
total_courses = c;
table.SumofMarks = zeros(r,1);
table.Percentage = zeros(r,1);
table.StudentGrade = repmat({''},r,1);
I = find(data<41);
[rowfail, colfail] = ind2sub(size(data),I);
fails = unique(rowfail);
% Sum of marks in different courses and their percentage.
format bank
Sum_of_Marks = sum(data,2);
Student_Percentage = Sum_of_Marks./total_courses;
T = horzcat(Sum_of_Marks,Student_Percentage);
N = length(Student_Percentage);
table.SumofMarks = Sum_of_Marks;
table.Percentage = Student_Percentage;
R = Student_Percentage;
for i = 1:N
if R(i)>=41 && R(i)<=99
table.StudentGrade{i} = 'A';
elseif R(i) >0 && R(i)<=40 || ismember(i,fails)
table.StudentGrade{i}= 'F';
end
end
writetable(table,filename)

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by