matlab基本语法
2019-08-15
13:12:07
%基本绘图 x = 0:0.5:2*pi; y = sin(x); plot(x,y); %第二个参数为矩阵 y1 = sin(x); y2 = cos(x); y3 = 0.02 * exp(x); y4 = x; y5 = 0.02 * tan(x); z = [y1;y2;y3;y4;y5]; plot(x,z); %两个参数都是矩阵 x1 = 0:0.01:2 * pi; x2 = -pi:0.01:pi; x = [x1;x2]; y1 = cos(x1); y2 = sin(x2); y = [y1;y2]; plot(x,y); %plot只有一个参数 x = linspace(0,2*pi,200); y = sin(x); plot(y); y2 = cos(x); plot(y2); y3 = y + i * y2; plot(y3); %plot有多个参数 x1 = linspace(0,2*pi,200); x2 = linspace(0,2*pi,100); y1 = cos(x1); y2 = sin(x2); plot(x1,y1,x2,y2); %plot含有的曲线选项 x = linspace(0,2*pi,100); y = sin(x); plot(x,y,'k');% r(红),g(绿),y(黄),m(品红),k(黑色),b(蓝色) plot(x,y,'.');%* . P <> plot(x,y,'--');%-- - -. :(连接方式) plot(x,y,'rp--'); %%图形的标注 x = linspace(0,2*pi,100); y = sin(x); plot(x,y); xlabel('x'); ylabel('y'); title('sin'); text(3,0,'y = sin(x)'); text(5,0.5,'x^2'); x1 = linspace(0,2*pi,200); x2 = linspace(0,2*pi,100); y1 = cos(x1); y2 = sin(x2); plot(x1,y1,x2,y2); legend('cos','sin'); xlim([-20,20]); x = linspace(0,2*pi,200); y = sin(x); plot(y); y2 = cos(x); plot(y2); y3 = y + i * y2; plot(y3); %坐标轴控制 axis equal%aquare是矩形 %%图形保持 x = 0:0.01:2*pi; y1 = sin(x); y2 = cos(x); hold on plot(x,y1,'r') plot(x,y2,'k') hold off %%窗口分割 x = 0:0.01:2*pi; y1 = sin(x); y2 = cos(x); y3 = tan(x); y4 = exp(x); subplot(2,2,1)%jia那个图形窗口绘制成2*2的窗口,使用第一窗口 plot(x,y1) subplot(222) plot(x,y2) subplot(223) plot(x,y3) subplot(224) plot(x,y4)
%基本绘图x = 0:0.5:2*pi;y = sin(x);
plot(x,y);
%第二个参数为矩阵y1 = sin(x);y2 = cos(x);y3 = 0.02 * exp(x);y4 = x;y5 = 0.02 * tan(x);
z = [y1;y2;y3;y4;y5];plot(x,z);
%两个参数都是矩阵x1 = 0:0.01:2 * pi;x2 = -pi:0.01:pi;x = [x1;x2];
y1 = cos(x1);y2 = sin(x2);
y = [y1;y2];plot(x,y);%plot只有一个参数x = linspace(0,2*pi,200);y = sin(x);plot(y);y2 = cos(x);plot(y2);y3 = y + i * y2;plot(y3);
%plot有多个参数x1 = linspace(0,2*pi,200);x2 = linspace(0,2*pi,100);y1 = cos(x1);y2 = sin(x2);plot(x1,y1,x2,y2);
%plot含有的曲线选项x = linspace(0,2*pi,100);y = sin(x);plot(x,y,'k');% r(红),g(绿),y(黄),m(品红),k(黑色),b(蓝色)plot(x,y,'.');%* . P <>plot(x,y,'--');%-- - -. :(连接方式)plot(x,y,'rp--');
%%图形的标注x = linspace(0,2*pi,100);y = sin(x);plot(x,y);xlabel('x');ylabel('y');title('sin');text(3,0,'y = sin(x)');text(5,0.5,'x^2');
x1 = linspace(0,2*pi,200);x2 = linspace(0,2*pi,100);y1 = cos(x1);y2 = sin(x2);plot(x1,y1,x2,y2);legend('cos','sin');xlim([-20,20]);
x = linspace(0,2*pi,200);y = sin(x);plot(y);y2 = cos(x);plot(y2);y3 = y + i * y2;plot(y3);%坐标轴控制axis equal%aquare是矩形
%%图形保持x = 0:0.01:2*pi;y1 = sin(x);y2 = cos(x);hold onplot(x,y1,'r')plot(x,y2,'k')hold off
%%窗口分割x = 0:0.01:2*pi;y1 = sin(x);y2 = cos(x);y3 = tan(x);y4 = exp(x);subplot(2,2,1)%jia那个图形窗口绘制成2*2的窗口,使用第一窗口plot(x,y1)subplot(222)plot(x,y2)subplot(223)plot(x,y3)subplot(224)plot(x,y4)