% Please understand! ! ! Can make up the best!
Function t4 ()
Chromaticity control center
%-Initiate initialization
Row=input ('Enter the number of students:');
Col=input ('Enter the number of courses:');
score=fix(rand(row,col)* 49)+49;
xh0 = 1:row;
kch 0 = 1:col;
for ii= 1:row
zcj_pre(ii)=sum_(score(ii,);
end
Original report; :')
disp([xh0 ' score zcj _ pre ']);
%-End initialization
% call Tongji 1
[c_max, index_max, c_min, index_min, c _ ave]= tonji 1 (score);
Disp ('average score statistics:')
Fprintf ('Course Average \ n');
% output in the above format
disp([kch0 ',round(c _ ave)']);
Disp ('Statistics of the highest scores of courses:')
Fprintf ('the highest student number of the course \ n');
For jj= 1:col
fprintf(' %d %d ',kch0(jj),c_max(jj))
For kk =1:length (index _ max {jj})
fprintf('%d ',index _ max { jj }(kk));
end
fprintf(' \ n ');
end
Disp ('course minimum score statistics:')
Fprintf ('Minimum number of students in the course \ n');
% output in the above format
For jj= 1:col
fprintf(' %d %d ',kch0(jj),c_min(jj))
For kk =1:length (index _ min {jj})
fprintf('%d ',index _ min { jj }(kk));
end
fprintf(' \ n ');
end
% call Tongji 23
[s_max, index_max, s_min, index_min, px]=tongji23 (score);
Disp ('Statistics of the highest scores of students' total scores:')
Fprintf ('Maximum Total Academic Number \ n');
% output in the above format
fprintf('%d ',s _ max);
disp(index _ max);
Disp ('Statistics on the lowest score of students' total score:')
Fprintf ('Minimum Total Academic Number \ n');
% output in the above format
fprintf('%d ',s _ min);
disp(index _ min);
disp('-');
Fprintf ('descending total score: \ n');
Fprintf ('Total Grade Number \ n');
% output in the above format
disp(px);
% deposited in zcj
zcj=px(:, 1); %zcj is in the main function space
% deposited in xh
xh=px(:,2); %xh is also in the main function space.
Function [c_max, index_max, c_min, index_min, c _ ave]= tonji 1 (fraction)
% c_max course col* 1 the highest score of the vector
The highest score of% index_max course corresponds to cell col* 1.
The lowest score of% c_min course col* 1 vector
The lowest score of% index_min course corresponds to cell col* 1.
% c_ave average col* 1 vector
[row,col]= size(score);
For jj= 1:col
[c_max(jj),index_max{jj}]=max_(score(:,jj));
[c_min(jj),index_min{jj}]=min_(score(:,jj));
c_ave(jj)=ave_(score(:,jj));
end
Function [s_max, index_max, s_min, index_min, px]=tongji23 (fraction)
The highest total score of% s_max col course.
% index_max col The highest total score of the course corresponds to the student number.
The lowest total score of% s_min col course.
The lowest total score of% index_min col course corresponds to the student number.
Matrix line * 2 is% px in descending order [COL course total score number]
[row,col]= size(score);
for ii= 1:row
zcj(ii)=sum_(score(ii,);
end
[s_max,index _ max]= max _(zcj);
[s_min,index _ min]= min _(zcj);
px = sort _ down(zcj);
Function y = sum _% self-made summation function, where x is the vector.
y = 0;
For ii= 1: length (x)
y = y+x(ii);
end
Function y = ave _% Self-designed average function, where x is the vector.
y = sum _/length(x);
Function [x_max, index]= max _% user-defined function.
% x_max: the maximum value in the vector x.
% index: the subscript vector corresponding to the maximum value in vector x (there may be multiple).
index =[];
x _ max = x( 1);
For ii= 1: length (x)
If x(ii)>=x_max
x _ max = x(ii);
end
end
For ii= 1: length (x)
If x(ii)==x_max
index=[index,ii];
end
end
Function [x_min, index]= min _% user-defined function.
% x_min: the minimum value in the vector x.
% index: the subscript vector corresponding to the minimum value in vector x (there may be multiple).
index =[];
x _ min = x( 1);
For ii= 1: length (x)
If x (ii) <: =x_min
x _ min = x(ii);
end
end
For ii= 1: length (x)
If x(ii)==x_min
index=[index,ii];
end
end
Function px=sort_down(x)
% px=[y_down index]
% y_down:x rows are arranged in descending order.
% index:x-sorted row label sequence
[row,col]= size(x);
If row = =1&; & ampCol~= 1% guarantees that x is a column vector.
x = x’;
end
Row = length (x);
index = 1:row;
px=[x,index ']; % constitutes a pre-sorted px.
% adopts selection sort 2:
For ii= 1: line-1
kk = ii
For jj=ii+ 1:row
If px(jj, 1)>px(kk, 1)
kk = jj
end
end
If kk~=ii
temp=px(kk,);
px(kk,)=px(ii,);
px(ii,)= temp
end
end