您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > MATLAB实验代码汇总
23varsglobalhelpMy_expsinX+Y_inputE-4AbcdAB_C_;3A=[123;456;789]y=[12+2*(7-4)]/(3^2)4A=15;B=20;C=A+Bc=a+bA=[123;456;789];B=[987;654;321];A*BA.*BA=10;B=20;C=A/BD=A\Ba=[1-23;45-4;5-67]A=[1,2;3,4]+i*[5,6;7,8]A=[1,2;3,4]+i[5,6;7,8]a=[123;342;523];a^2a.^2clearX=[12;89;36];X(:)A=[123];B=[456];C=3.^AD=A.^B5t=-1:0.01:1;y=(sqrt(3)/2).*exp((-4).*t).*sin(t.*4*sqrt(3)+(pi/3))1clcclearA=[1234-4;34787;3657];B=[13-1;203;3-27];a=A+6*B,I=eye(3),b=A^2-B+I,c=A*B,d=A.*B,e=A^3,f=A.^3,g=[A,B],h=[(A([1,3],:));B^2]2clcclearA=[12345;678910;1112131415;1617181920;2122232425];B=[3016;17-69;023-4;970;41311];C=A*B,D=C([345],[23])3clcclearA=[2310-0.7780;41-45655;325032;6-9.54543.14];B=A([1:3],:);C=A(:,[1:2]);D=A([234],[12]);E=B*C;a=ED,b=E&D,c=E|D,d=~E|~D,e=(A=10&A25)4clcclear%9090A=magic(3),B=rot90(A),C=rot90(A,3)%B90C905clcclearA=[12222222222],B=cumprod(A),%AC=cumsum(B),%BS=max(C),%6clcclearA=[11011162129121722381318234714192456152025];B=reshape(A,5,5)C1=B(2,[23])C2=B([234],4)C3=B([45],[123])1.a=reshape(100:999,30,30);b=rem(a,21)%c=find(b==0)length(c)%2.ch='FrIeNd123'd=find(ch='A'&ch='Z')ch(d)=[]3.%ch='InGBusagequotationmarksareusuallysingel:''fire!'''5.1A{1,1}=1;A{1,2}='Brenden';A{2,1}=reshape(1:9,3,3);A{2,2}={12,34,2;54,21,3;4,23,67};upper(A{1,2})%5.2.1A{1,1}=1;A{1,2}='Brenden';A{2,1}=reshape(1:9,3,3);A{2,2}={12,34,2;54,21,3;4,23,67};A(3)=[]%5.2.2A{1,1}=1;A{1,2}='Brenden';A{2,1}=reshape(1:9,3,3);A{2,2}={12,34,2;54,21,3;4,23,67};A{3}=[]%{}6.a=rand(4,3)%4*30,1b=mean(a)%iaic=median(a)%iaib1=mean(b)c1=median(c)d=max(a)d1=max(d)%e=min(a)e1=min(e)%[i1,j1]=find(a==d1)%[i2,j2]=find(a==e1)%t=sum(a')x=sum(a)y=sum(x)%sort(a)%Asort(a,2,'descend')%A1.1s=1;forn=1:100s=s*n;if(s10^100)break;endenda=sprintf('n=%d',n);b=sprintf('%d!=%e1e100',n,s);disp(a)disp(b)1.2n=1;s=1;while(s=10^100)s=s*n;n=n+1;enda=sprintf('n=%d',n-1);b=sprintf('n!=%e1e100',s);disp(a)disp(b)2f(1)=1;f(2)=0;f(3)=1;forn=4:50f(n)=f(n-1)-2*f(n-2)+f(n-3);end[MAX,x]=max(f)[MIN,y]=min(f)SUM=sum(f)positive=length(find(f0))zero=length(find(f==0))negative=length(find(f0))3a(1)=1;a(2)=1;fori=1:10000a(i+2)=a(i)+a(i+1);ifa(i)10000break;endenddisp(['i=',num2str(i)])disp(['a(i)=',num2str(a(i))])1x=1491625364964811002ans=1001.1score=input('pleaseinputgrade=');if(score100|score0|rem(score,0.5)~=0)disp('');elseif(score=90&score=100)disp('thegrade=A!');elseif(score=80&score=89)disp('thegrade=B!');elseif(score=70&score=79)disp('thegrade=C!');elseif(score=60&score=69)disp('thegrade=D!');elseif(score60)disp('thegrade=E!');endend1.2score=input('pleaseinputgrade=');if(score=100&score=0&rem(score,0.5)==0)switchfix(score/10)case{9,10}disp('grade=A')case{8}disp('grade=A');case{7}disp('grade=C');case{6}disp('grade=D');otherwisedisp('grade=E');endelsedisp('');end2clearclcx=fix(50*(rand(1)-rand(1)))y=fix(50*(rand(1)-rand(1)))k=input('','s');switch(k)case{'+'}a=x+y;case{'-'}a=x-y;case{'*'}a=x*y;case{'/'}a=x/y;otherwisedisp('');break;endstc=sprintf('a=x%sy=%d',k,a)3clearclcx=[];y=[];x=input('x');fork=1:length(x)ifx(k)0&x(k)~=-3y(k)=x(k).^2+x(k)-6;elseifx(k)=0&x(k)10&x(k)~=2&x(k)~=3y(k)=x(k).^2-5*x(k)+6;elsey(k)=x(k).^2-x(k)-1;endendfori=1:length(y)disp(['y(',num2str(x(i)),')','=',num2str(y(i))]);;end1.functionvarargout=chengji(a,b)[x,y]=size(a);[xx,yy]=size(b);ifxx==yy&x==y&x==xxvarargout{1}=a*b;varargout{2}=a.*b;elseifx==xx&y==yyvarargout{1}=a.*b;disp('')varargout{2}=0;elseifx==yy&xx==ydisp('')varargout{1}=a*b;varargout{2}=b*a;elseifx==yy||xx==ytryvarargout{1}=a*b;disp('')varargout{2}=0;catchvarargout{1}=b*a;disp('')varargout{2}=0;endelseerror('')endendendend2.functiony=qiuhe(a)y=[];[m,n]=size(a);ifm==1s=0;fork=1:ns=s+a(1,k);endy=s;elseforj=1:ns=0;fori=1:ms=s+a(i,j);endy(1,j)=s;endend3.functions=jiecheng(n)s=1;ifn==0s=1;elseifn0error('n0')elsefori=1:ns=s*i;endendendfunctiony=temf(a)iflength(a)2y=a;elsey=max(a)-min(a);end7.1clearall;clc;qname=input('Enterfilecontainingquestion:','s');ip=fopen(qname,'rt');if(ip0)disp('couldnotopeninputfile')endop=fopen('qq.txt','wt');if(op0)disp('couldnotopenoutputfile');endq=fgetl(ip);while(ischar(q))fprintf('%s\n',q)a=input('AnswerY(yes)orN(not):','s');while((a~='Y')&&(a~='N'))a=input('AnswerY(yes)orN(not):','s');endfprintf(op,'%s\nAnswer:%s\n',q,a);q=fgetl(ip);endfclose(ip);fclose(op);7.2clearall;clc;f=fopen('a.txt');h=fopen('aa.txt','w');fwrite(h,upper(char(fread(f,inf,'char'))),'char');fclose(f);fclose(h);7.3a=1:5;fid=fopen('fdat.bin','w');fwrite(fid,a,'int16');status=fclose(fid);fid=fopen('fdat.bin','r');status=fseek(fid,6,'bof');b=fread(fid,1,'int16');position=ftell(fid);status=fseek(fid,-4,'cof');c=fread(fid,1,'int16');status=fclose(fid);bcPosition1.clear,clcx=0:1:4*pi;y=sin(x).*exp(-x/5);xi=0:0.3:4*pi;y1=interp1(x,y,xi,'nearset');y2=interp1(x,y,xi,'linear');y3=interp1(x,y,xi,'spline');y4=interp1(x,y,xi,'cubic');plot(x,y,'-m',xi,y1,'*r',xi,y2,'ok',xi,y3,'^b',xi,y4,'+g')legend('','','','','')title('','fontname','','fontsize',20)xlabel('x','fontname','','fontsize',16)ylabel('y','fontname','','fontsize',16)2.clear,clct=[1315171920];sex=[0,1]';y=[
本文标题:MATLAB实验代码汇总
链接地址:https://www.777doc.com/doc-8704830 .html