Program to solve problem description:
First, create a structure containing the names and numbers of ten students and the grades of six subjects for each student, and calculate the total grades and average grades of the ten students respectively. Finally, sort the ten students according to the total grades, and order in the command window Print out the names of students 1-10.
The program code is as follows:
person=struct('name',{'liu','hui','ying','li','bee','fly','kik','sun','ming','see'},'xuehao',{101,102,103,104,...
105,106,107,108,109,110},'math',{80,81,82,60,55,90,48,89,78,96},'MATLAB',{78,88,...
89,90,96,86,82,70,60,88},'wuli',{85,81,82,67,55,80,88,89,88,96},'English',{78,88,...
69,93,96,85,82,76,60,77},'huaxue',{85,81,62,66,55,80,78,89,98,96},'shengwu',{75,81,92,67,55,82,88,89,88,96});
disp(person);
disp(person(1))
x1=[person.math];
s=[person.math; person.MATLAB; person.wuli; person.English; person.huaxue; person.shengwu];
n={person.name};
l=length(x1);
disp(n)
disp('各学生的总成绩分别为:')
x=sum(s);
disp(x)
a=x/6;
disp('各学生的平均成绩分别为:')
disp(a)
[B,suoy]=sort(x,'descend');
disp('排列名次为:')
for i=1:10
e=B(i);
d=find(x==e);
disp(n(d))
end
The result of the program running is as follows:
Friends who see this, don’t forget to like it before leaving!
Follow bloggers to learn more basic knowledge of MATLAB!