MATLAB 大作业求助

MATLAB 大作业求助,第1张

clear all

close all

clc

A=zeros(3,5,2)

A(:,:,1)=[2001 98 94 80 52002 105 97 87 62003 121 110 89 8]

A(:,:,2)=[2001 99 98 85 102002 113 101 87 122003 120 115 80 15]

for i=1:3 %显示结果依次为平均新生、学士毕业生、硕士毕业生及博士毕业生

infor_mean=mean(A(:,2:5,1))

end

infor_mean=infor_mean

total_new=zeros(3,1)%第二问

for k=1:3

total_new(k)=A(k,2,1)+A(k,2,2)

end

total_new=total_new

total_M=sum(A(:,4,1))+sum(A(:,4,2))%第三问

total_SMD=sum(A(:,3:5,1))+sum(A(:,3:5,2))%第四问

total=sum(total_SMD)

year_M=zeros(3,1)%第五问

for j=1:3

year_M(j)=A(j,4,1)+A(j,4,2)

end

year_M_max=max(year_M)

num=find(year_M==year_M_max)

switch num

case 1

disp('电机系信息系合计有最多的硕士毕业生是2001')

case 2

disp('电机系和信息系合计有最多的硕士毕业生是2002')

case 3

disp('电机系和信息系合计有最多的硕士毕业生是2003')

end

year_S=zeros(3,1)%第六问

for j=1:3

year_S(j)=abs(A(j,3,1)-A(j,3,2))

end

year_S_max=max(year_S)

num2=find(year_S==year_S_max)

switch num2

case 1

disp('电机系和信息系的学士毕业生差额最大是2001')

case 2

disp('电机系和信息系的学士毕业生差额最大是2002')

case 3

disp('电机系和信息系的学士毕业生差额最大是2003')

end

year_N=zeros(3,1) %第七问

for j=1:3

year_N(j)=A(j,3,2)-A(j,3,1)

end

year_N_matrix=find(year_N>0)

length_year_N_matrix=length(year_N_matrix)

for k=1:length_year_N_matrix

disp(A(year_N_matrix(k),1,1))disp('电机系收的新生数目比信息系多')

end

for i=1:3

ratios(i)=A(i,3,1)./A(i,2,1)

end

mean_ratio=mean(ratios)

结果已经运行,没检验对错,自己检验吧,这个真不需要注释,全是基本 *** 作,亲!

1.

A=[1 4 8 13-3 6 -5 -92 -7 -12 -8]

>>A

A =

1 4 8 13

-3 6-5 -9

2-7 -12 -8

>>B=[5 4 3 -26 -2 3 -8-1 3 -97]

>>B

B =

5 4 3 -2

6-2 3 -8

-1 3-97

>>C1=A*B'C2=A'*BC3=A.*B

C3 =

51624 -26

-18 -12 -15 72

-2 -21 108 -56

>>C2

C2 =

-1516 -24 36

63 -1793 -105

22 6 117 -60

194684 -10

>>C1

C1 =

19 -8230

12 27 3

-385429

>>inv(C1)

ans =

0.00620.0400 -0.0106

-0.00460.01690.0030

0.01680.02090.0150

>>inv(C2)

Warning: Matrix is close to singular orbadly scaled.

Results may be inaccurate. RCOND = 8.997019e-019.

ans =

1.0e+015 *

-0.9553 -0.2391 -0.1997 0.2700

0.96670.24200.2021 -0.2732

-0.4473 -0.1120 -0.0935 0.1264

-1.1259 -0.2818 -0.2353 0.3182

>>pinv(C3)

ans =

-0.0007 -0.0049 -0.0017

0.05710.0125 -0.0109

0.01790.01120.0067

0.01310.0171 -0.0008

2.

(1)

>>student2012=struct('number',{'20100501','20100502','20100503','20100504','20100505','20100506','20100507','20100508','20100509'},'name',{'张晓霞','郭凯','周明辉','王雪梅','郭志刚','姚大志','王佳薇','黎明','王玲'},'course',{{'高等数学''计算机基础''工程制图''线性代数''体育'}},'score',{[69 87 78 90 60],[82 90 88 100 89],[88 92 91 78 69],[7580 78 70 88],[46 89 69 87 78],[81 74 52 69 79],[59 95 80 78 87],[100 70 89 9591],[78 82 94 59 79]})

>>student2012

student2012 =

1x9 struct array with fields:

number

name

course

score

(2)

>>student2012(1).mean=[mean(student2012(1,1).score),mean(student2012(1,2).score),mean(student2012(1,3).score),mean(student2012(1,4).score),mean(student2012(1,5).score),mean(student2012(1,6).score),mean(student2012(1,7).score),mean(student2012(1,8).score),mean(student2012(1,8).score)]

>>student2012(1).mean

ans =

76.8000 89.8000 83.6000 78.2000 73.8000 71.0000 79.8000 89.0000 89.0000

>>student2012

student2012 =

1x9 struct array with fields:

number

name

course

score

mean

(3)

提取数学成绩

>>for k=1:9

number(k)=student2012(k).score(1)

end

>>

>>number

number =

6982 887546 8159 100 78

计算不及格率

>>a=0

>>for k=1:9

number(k)=student2012(k).score(1)

if number(k)<60 a=a+1

end

end

>>c=a/9

>>c

c =

0.2222

(3)

①找到存在不及格科目的域,并把找到的域的编号设为1

>>for k=1:9

if(student2012(k).score(1)<60|student2012(k).score(2)<60|student2012(k).score(3)<60|student2012(k).score(4)<60|student2012(k).score(5)<60)

e(k)=1

else

e(k)=0

end

end

e =

0 0 00 1 11 0 1

②删除找到的域

>>m=9

>>for k=1:9

if(e(k))

end

end

>>for k=1:9

end

>>m=1

>>for k=1:9

if(e(k))

student2012(m)=[]

m=m+0

else

m=m+1

end

end

m =

2

m =

3

m =

4

m =

5

student2012 =

1x8 struct array with fields:

number

name

course

score

mean

m =

5

student2012 =

1x7 struct array with fields:

number

name

course

score

mean

m =

5

student2012 =

1x6 struct array with fields:

number

name

course

score

mean

m =

5

m =

6

student2012 =

1x5 struct array with fields:

number

name

course

score

mean

m =

6

(4)

>>student1{1,1}=['20100502''20100508']

>>student1{2,1}={'郭凯''黎明'}

>>student1{1,2}={'高等数学''计算机基础''工程制图''线性代数''体育'}

>>student1{2,2}={[82 90 88 10089][100 70 89 95 91]}

>>student1

student1 =

[2x8 char]{1x1 cell}

{1x1 cell} {2x1 cell}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8097731.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存