⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plotexam2.m

📁 MATLAB的课件集合
💻 M
字号:
%%%绘图引例子
t=(0:100)/100*pi; 
y=sin(t).*sin(9*t);
subplot(2,1,1),plot(t,y,'r.'),axis([0,pi,-1,1]),title('子图1')
subplot(2,1,2),plot(t,y),axis([0,pi,-1,1]),title('子图图2')

%%%多条曲线
clf
figure(1)
t=(0:pi/50:2*pi)';
k=0.4:0.1:1;  
Y=cos(t)*k;  
plot(Y)
figure(2)
plot(t,Y)	

%%%色彩线性
figure(1)
t=(0:pi/100:pi)';		
y1=sin(t)*[1,-1];		
y2=sin(t).*sin(9*t);	
plot(t,y1,'r:',t,y2,'b')
axis([0,pi,-1,1])
figure(2)
hold on
plot(t,y1,'r:')
plot(t,y2,'b')
hold off

%%数据点型
clf
t=(0:pi/100:pi)';  
y1=sin(t)*[1,-1];  
y2=sin(t).*sin(9*t); 
plot(t,y1,'r:',t,y2,'b')
axis([0,pi,-1,1])
figure(4)
t1=pi*(0:9)/9;
y3=sin(t1).*sin(9*t1);
plot(t,y2,'b',t1,y3,'bp')
axis([0,pi,-1,1]) 


%%各种轴控制指令不同影响
clf
t=0:2*pi/99:2*pi;
x=1.15*cos(t);y=3.25*sin(t);	%
subplot(2,3,1),plot(x,y),axis normal,grid on,
title('Normal and Grid on')
subplot(2,3,2),plot(x,y),axis equal,grid on,title('Equal')
subplot(2,3,3),plot(x,y),axis square,grid on,title('Square')
subplot(2,3,4),plot(x,y),axis image,box off,title('Image and Box off')
subplot(2,3,5),plot(x,y),axis image fill,box off
title('Image and Fill')
subplot(2,3,6),plot(x,y),axis tight,box off,title('Tight')  

%图形标识
clf
x=0:0.1:1;         
y=x.*exp(-x); 
plot(x,y);
xlabel('x'),ylabel('y')  %图形标识
title('y=x*exp(-x)')     %图形标识

%%%精细控制
clf
t=pi*(0:1/100:1);beta=asin(1);
y=1-exp(-2*t).*sin(5*t+beta);
plot(t,y)
text(3.0,1.14,'\bf\alpha = 2')
text(3.0,1.10,'\rm\omega = 5')
xlabel('\fontsize{14}\bft')
ylabel('\fontsize{14}y')
title('\rm y=1-e^{-\alphat}sin(\omegat+\beta)')

%%%双坐标绘图
clf
t=0:0.02:3;
xi=0.5;wn=5;
sxi=sqrt(1-xi^2);
sita=atan(sxi/xi);
wd=wn*sxi;
y1=1-exp(-xi*wn*t).*sin(wd*t+sita)/sxi;
y2=wn*exp(-xi*wn*t).*sin(wd*t)/sxi;
plotyy(t,y1,t,y2)

%%%绘子图
t=(pi*(0:1000)/1000)';
y1=sin(t);y2=sin(10*t);y12=sin(t).*sin(10*t);
subplot(2,2,1),plot(t,y1);axis([0,pi,-1,1])
subplot(2,2,2),plot(t,y2);axis([0,pi,-1,1])
subplot('position',[0.2,0.05,0.6,0.45])		
plot(t,y12,'b-',t,[y1,-y1],'r:');axis([0,pi,-1,1]) 

%%%plot3绘图
clf
t=(0:0.02:2)*pi;x=sin(t);y=cos(t);z=cos(2*t);
plot3(x,y,z,'b-',x,y,z,'bd')
box on
legend('链','宝石') 

%%mesh绘图
clf;
x=-4:4;y=x;
[X,Y]=meshgrid(x,y)
Z=X.^2+Y.^2;	
figure(1)
mesh(X,Y,Z);
colormap(cool)
xlabel('X'),ylabel('y'),zlabel('z')
figure(2)
mesh(Z)


%%镂空
clf
[X0,Y0,Z0]=sphere(30);
X=2*X0;Y=2*Y0;Z=2*Z0;
surf(X0,Y0,Z0);
shading interp
hold on,mesh(X,Y,Z),colormap(hot),hold off
hidden off
axis equal,axis off 
%%%%彗星转地球

clf
shg;R0=1;
a=12*R0;b=9*R0;T0=2*pi;
T=5*T0;dt=pi/100;t=[0:dt:T]';
f=sqrt(a^2-b^2);
th=12.5*pi/180;
E=exp(-t/20);
x=E.*(a*cos(t)-f);y=E.*(b*cos(th)*sin(t));z=E.*(b*sin(th)*sin(t));
plot3(x,y,z,'g')
[X,Y,Z]=sphere(30);X=R0*X;Y=R0*Y;Z=R0*Z;
grid on,hold on,surf(X,Y,Z),shading  interp
x1=-18*R0;x2=6*R0;y1=-12*R0;y2=12*R0;z1=-6*R0;z2=6*R0;
axis([x1 x2 y1 y2 z1 z2])
view([117 37]),comet3(x,y,z,0.02),hold off 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -