Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

matlab - Grading system in excel sheet based on marks

I am trying to paste grades in 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 have less than 70 then want to show F

UPDATED CODE

        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./total_courses;
    T = horzcat(Sum_of_Marks,Student_Percentage);
    
    
    N = length(Student_Percentage);
    table.SumofMarks = Sum_of_Marks;
    table.Percentage = Student_Percentage;
    
    for i = 1:63
        sheet1=readtable(filename);
        mark=sheet1{i,{'CALCULUS','DISCRETE','ECONOMICS','ISLAMIAT','STATISTICS'}};
        
        if mark(mark<40)
            grade='F';
            sheet1(i,'StudentGrade')=cellstr(grade);
           else 
            continue
        end
    end
    writetable(table,filename)
    xlswrite(filename,T,1, 'H2')
    xlswrite(filename,grade,1,'J2')

these are the errors which I get

        Error using getRowIndices (line 75)
    Row index exceeds table dimensions.
    
    Error in table/subsrefBraces (line 17)
    [rowIndices,numRowIndices] =
    getRowIndices(t, s(1).subs{1});
    
    Error in table/subsref (line 60)
        [varargout{1:nargout}] =
        subsrefBraces(t,s);
    
    Error in lab4 (line 38)
        mark=sheet1{i,{'CALCULUS','DISCRETE','ECONOMICS','ISLAMIAT','STATISTICS'}}; 

i tried this but this code doesnt work

how i do this

i paste link where my file is located.. and I want if any student get less than 40 marks in any subject then want to show F grade.. this code shows if total marks is less than 40 .. where as I want to show if marks is less than 40 in any subject

this is the excel file

https://drive.google.com/file/d/1VQ8XxAQPu6reY0SCNV9Rxt65w1koduGA/view?usp=sharing

question from:https://stackoverflow.com/questions/65640692/grading-system-in-excel-sheet-based-on-marks

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't have Excel installed, so I can't check the part about reading and writing to Excel, but you should replace

if R>=80
   table.StudentGrade{i} = 'A';
elseif R>=70 
   table.StudentGrade{i} = 'B';
elseif R <70
    table.StudentGrade{i}= 'F';
end

with

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...