x = -2 * pi : 0.1:2*pi;y1 = sin(x);y2 = cos(x);plot(x, y1, '-b');hold onplot(x, y2, '-r');xlabel('x')ylabel('y')text(0,0,'(0,0)')legend('sin x','cos x')1.2.3.4.5.6.7.8.9.10.
t = 0:pi/180:4*pi;x = 16*sin(t).^3y = 13 * cos(t) - 5*cos(2*t)... -2*cos(3*t)- cos(4*t);plot(x-3,y,'-r',x+3,y,'-b');xlabel('x');ylabel('y');axis([-20,20,-20,15]);title('Two Hearts')legend('U','I')1.2.3.4.5.6.7.8.9.10.
曲线图 plot: plot(x,y); plot(x,y,s), plot(x1,y1,s1,x2,y2,s2,…)
b blue · point - solidg green o circle : dottedr red x x-mark -. dashdotc cyan + plus -- dashedm magenta * star (none) no liney yellow s squarek black d diamondw white v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram1.2.3.4.5.6.7.8.9.10.11.12.13.
x = 10*2.^[0:6];y = [100 150 225 340 ... 510 765 1150];loglog(x,y,'.-r')xlim([0.5e1,0.8e3])ylim([0.8e2,1.4e3])xlabel('x');ylabel('y');1.2.3.4.5.6.7.8.
极坐标: polar
theta = 0:pi/180:4*pi;r = 1-sin(theta);polar(theta,r,'-r');1.2.3.
4. 三维曲线图
t = 0:pi/50:10*pi;x = sin(t);y = cos(t);z = t;plot3(x, y, z)title('Helix')xlabel('sin t')ylabel('cos t')zlabel('t')grid on1.2.3.4.5.6.7.8.9.10.
[x,y] = meshgrid(-pi : 0.1 : pi);z = sin(x).*cos(y);mesh(x, y, z)surf(x,y,z)xlabel('x')ylabel('y')zlabel('z')title('sin x sin y')1.2.3.4.5.6.7.8.
[x, y] = meshgrid(1:3, 1:3);xy1.2.3.
[x, y] = meshgrid(1:3, 1:3);xyrsq = (x-2).^2 + (x-2).^21.2.3.4.
[x, y] = meshgrid(1:3, 1:3);xyrsq = (x-2).^2 + (x-2).^2r = sqrt(rsq)1.2.3.4.5.
6. M函数格式
function [output 1, …] = functionname(input1, …)
MatLab command 1;
MatLab command 2;
function area = rectarea(L, W)area = L .* W1.2.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删