%matlab第7节 matlab画图
%plot函数 example plot(x,y) x=[1 2 3] y=[4 5 6 ] //意思是点[1,4] 点[2,5] 点[3,6]
%matlab 会用线,把这些点连接起来
% x=[1 2 3 ];
% y=[4 5 6 ];
% plot(x,y)
% %二次函数
% x=-3:3;
% y=x.*x;%在matlab中点乘是a*a,乘法是矩阵相乘
% plot(x,y);
% %上边的改版
% x=-3:0.1:3;
% y1=x.^2;
% y2=x.^3;
% plot(x,y1,'green-o',x,y2,'red');
% axis equal%axis equal :为了把x轴单位长度和y轴单位长度统一
%
% %直方图bar()函数
% y=[75 91 105 123.5 131 150 179 203 240 275 280 ];
% bar(y);
% x=2000:2010;
% bar(x,y);
%matlab的3D画法
% theta=0:pi/50:6*pi;
% x=cos(theta);
% y=sin(theta);
% plot(x,y);
% z=0:300;
% plot3(x,y,z);%plot3表示画3D图像
% %matlab第8节
% x1=-5:0.1:5;
% y1=x1.*2;
% plot(x1,y1);
%
% hold on;% 把两个图结合在一起
%
% x2=-5:0.1:5
% y2=x2.^3;
% plot(x2,y2);
%
% grid on;%显示出表格
% %title函数('');
% title('x^2 vs x^3');
% xlabel('x-axis');%xlabel 是在x轴写标题
% ylabel('y-axis');%ylabel 是在y轴写标题
% %subplot函数 subpolt(2,3,1):分割成两行,每行3个,选第一个
%
% x=-4:0.1:4;
%
% y1=sin(x);
% y2=sin(2.*x);
% y3=sin(3.*x);
% y4=sin(4.*x);
%
% subplot(2,2,1);
% plot(y1);
% title('y=sin(x)');
%
% subplot(2,2,2);
% plot(y2);
% title('y=sin(2x)');
%
% subplot(2,2,3);
% plot(y3);
% title('y=sin(3x)');
%
% subplot(2,2,4);
% plot(y4);
% title('y=sin(4x)');
%上面那个了例子的改版
% x=-4:0.1:4;
%
% y1=cos(x);
% y2=cos(2.*x);
% y3=sin(4.*x);
%
% subplot(2,2,1);
% plot(x,y1);
% title('y=cos(x)');
%
% subplot(2,2,2);
% plot(x,y2);
% title('y=cos(2x)');
%
% subplot(2,2,[3,4]);%用[3,4]表示这两个区间合并
% plot(x,y3);
% title('y=sin(4x)');
% %画曲面用surf(下,有,z)函数
% x=-3:0.1:3;
% y=-3:0.1:3;
% [X,Y]=meshgrid(x,y);%meshgrid函数是用两个坐标轴上的点在平面上画格
%
% Z=X.^2+Y.^2;
% surf(X,Y,Z);
%matlab第九节(最后一节,完结撒花)
% %sin函数的动态图
% X=-2*pi:0.1:2*pi;
% Y=sin(X);
%
% h=plot(X,Y);
% 或写成while true
% for i=1:10000
% X=X+0.1;
% Y=sin(X);
% set(h,'XData',X,'YData',Y);%注意XData中的X和D必须大写,YData中的Y和D必须大写。
% drawnow;%实时画出来
% end
% %弹簧的动态图
% theta=-10*pi:0.1:10*pi
% X=cos(theta);
% Y=sin(theta);
% Z=theta;
%
% h=plot3(X,Y,Z);
% axis([-1,1,-1,1,-40,40]);%固定坐标轴
% while true
% for i=1:100
% Z=Z*0.98;
% set(h,'XData',X,'YData',Y,'ZData',Z);
%
% drawnow;
% end
%
% for i=1:100
% Z=Z/0.98;
% set(h,'XData',X,'YData',Y,'ZData',Z);
%
% drawnow;
% end
% end
%画一个逆时针的时钟
t=0:pi/100:2*pi;
X=cos(t);
Y=sin(t);
plot(X,Y);
hold on;
axis equal;
lineX=[0,1];
lineY=[0,0];
h=plot(lineX,lineY);
theta=0;
while true
theta=theta+0.001;
lineX(2)=cos(theta);
lineY(2)=sin(theta);
set(h,'XData',lineX,'YData',lineY);
drawnow;
end
评论0