一:把excel表格整理好,放在桌面上,
2:找到文件路径
3:代码
4:以经过验证,可以准确计算
clc
clear
%excel存的路径,第一学期
First_Semester=csvread('C:\Users\123\Desktop\2020级二班行政班成绩第一学期(1).csv');
Second_Semester=csvread('C:\Users\123\Desktop\2020级行政班成绩第二学期(1).csv');
%core 总的分数
A=First_Semester;
B=Second_Semester;
%General第一列专业课成绩,第二列通识课成绩
Class_size=55;%班级人数
Course_num_1=16;%第一学期专业课
Course_num_2=16;%第二学期专业课
core_num_1=9;%第一学期核心专业课
General_num_1=7;%第一学期通识课专业课
core_num_2=11;%第二学期核心专业课
General_num_2=5;%第二学期通识课专业课
core_duty=0.7;%核心课占比
General_duty=0.3;%通识课占比
semester=2;%两学期
[total]=grade(Class_size,Course_num_1,core_num_1,General_num_1,Course_num_2,core_num_2,General_num_2,core_duty,General_duty,First_Semester,Second_Semester,semester);
% % %total
% % % 第一列,第一学期核心课
% % %第二列,第一学期通识课
% % %第三列,第二学期核心课
% % %第四列,第二学期通识课
% % % 第五列,第一二学期专业课总分数
% % %第六列,第一二学期通识课总分数
% % %第七列,第一二学期专业课总学分
% % %第八列,第一二学期通识课总学分
% % %第九列,第一学期总成绩
% % %第十列,第二学期总成绩
% % %第11列,第一二学期总成绩
% % %第12列,总成绩*0.6
function [a18]=grade(Class_size,Course_num_1,core_num_1,...
General_num_1,Course_num_2,core_num_2,General_num_2,core_duty,General_duty,A,B,num)
if num==2
Class_size=Class_size+1;
a1=A(Class_size,[4:Course_num_1+4-1]);
a2=A([1:(Class_size-1)],[4:Course_num_1+4-1]);
a3=[];
a4=[];
a5=[];
a6=[];
a7=[];
a8=[];
a9=[];
a10=[];
a11=[];
a14=[];
a16=[];
jj=1;
jjjj=1;
core_credit=0;
core_num=core_num_1;
General_num=General_num_1;
General_credit=0;
for i=1:(Class_size-1)
jj=0;
for j=1:Course_num_1
a3(i,j)=a2(i,j)*a1(j);
if a2(i,j)==0
jj=jj+1;
a5(i,jj)=j;
end
end
end
Legend=size(a5,2);
for i=1:(Class_size-1)
temp=0;
temp1=0;
for j=1:core_num_1
temp=a3(i,j)+temp;
for jjj=1:Legend
if j==a5(i,jjj)
temp1=temp1+a1(j);
end
end
end
a6(i,1)=temp1;
a4(i,1)=temp;
temp=0;
temp1=0;
for j=(core_num_1+1):Course_num_1
temp=a3(i,j)+temp;
for jjj=1:Legend
if j==a5(i,jjj)
temp1=temp1+a1(j);
end
end
end
a4(i,2)=temp;
a6(i,2)=temp1;
end
for j=1:2
for i=1:(Class_size-1)
a23(i,j)=a4(i,j)
end
end
for i=1:core_num_1
core_credit=core_credit+a1(i);
end
for i=(core_num_1+1):Course_num_1
General_credit=General_credit+a1(i);
end
for i=1:(Class_size-1)
a7(i,1)=core_credit-a6(i,1);
a7(i,2)=General_credit-a6(i,2);
end
for i=1:(Class_size-1)
a9(i,1)=a4(i,1)/a7(i,1)*core_duty;
a9(i,2)=a4(i,2)/a7(i,2)*General_duty;
end
for i=1:(Class_size-1)
a8(i)=a9(i,1)+a9(i,2);
end
end
a8=a8';
Class_size=Class_size;
Course_num=Course_num_2;
a1=B(Class_size,[4:Course_num_2+4-1]);
a2=B([1:(Class_size-1)],[4:Course_num_2+4-1]);
a3=[];
a4=[];
a5=[];
a6=[];
a10=[];
a11=[];
a18=[];
jj=1;
jjjj=1;
core_credit=0;
core_num=core_num_2;
General_num=General_num_2;
General_credit=0;
for i=1:(Class_size-1)
jj=0;
for j=1:Course_num_2
a3(i,j)=a2(i,j)*a1(j);
if a2(i,j)==0
jj=jj+1;
a5(i,jj)=j;
end
end
end
Legend=size(a5,2);
for i=1:(Class_size-1)
temp=0;
temp1=0;
for j=1:core_num_2
temp=a3(i,j)+temp;
for jjj=1:Legend
if j==a5(i,jjj)
temp1=temp1+a1(j);
end
end
end
a6(i,1)=temp1;
a4(i,1)=temp;
temp=0;
temp1=0;
for j=(core_num_2+1):Course_num_2
temp=a3(i,j)+temp;
for jjj=1:Legend
if j==a5(i,jjj)
temp1=temp1+a1(j);
end
end
end
a4(i,2)=temp;
a6(i,2)=temp1;
end
for j=1:2
for i=1:(Class_size-1)
a22(i,j)=a4(i,j)
end
end
a16=a22+a23;
for j=1:2
for i=1:(Class_size-1)
a20(i,j)=a4(i,j)
end
end
for i=1:core_num_2
core_credit=core_credit+a1(i);
end
for i=(core_num_2+1):Course_num_2
General_credit=General_credit+a1(i);
end
for i=1:(Class_size-1)
a14(i,1)=core_credit-a6(i,1);
a14(i,2)=General_credit-a6(i,2);
end
for i=1:(Class_size-1)
a25(i,1)=a20(i,1)/a14(i,1)*core_duty;
a25(i,2)=a20(i,2)/a14(i,2)*General_duty;
end
for i=1:(Class_size-1)
a26(i,1)=a25(i,1)+a25(i,2);
end
for j=1:2
for i=1:(Class_size-1)
a15(i,j)=a14(i,j)+a7(i,j) ;
end
end
for i=1:(Class_size-1)
a17(i,1)=a16(i,1)/a15(i,1)*core_duty;
a17(i,2)=a16(i,2)/a15(i,2)*General_duty;
end
for i=1:(Class_size-1)
a18(i,1)=a17(i,1)+a17(i,2);
end
a19=a18*0.6;
a18=[a9,a25,a16,a15,a8,a26,a18,a19];
end