Plots

  • Line style
    • '-', '--', ':', '-.'
  • Marker
    • 'o', '+', '*','.', 'x', 's', 'd', '^', 'v','>', '<', 'p', 'h',
  • Color
    • 'y', 'm', 'c', 'r','g', 'b', 'w', 'k'
  • Examples
    • '-o','--',':','g','b--o','c*','--gs'
In [5]:
x = linspace(-4*pi, 4*pi, 100);
y = sin(x);
plot (x, y,':om');
In [6]:
plot(x,y,'-o',...
    'LineWidth',1,...
    'MarkerSize',2,...
    'MarkerEdgeColor','c',...
    'MarkerFaceColor',[0.5,0.5,0.5])
In [7]:
plot(x,y,'Color',[0.5,0.1,0.7])
In [8]:
x = linspace(-4*pi, 4*pi, 100);
plot (x, sin (x));
xlabel('x-axis')
ylabel('y-axis')
title('Sine function')
axis([-12, 12, -1.5, 1.5])
In [11]:
clear all
x = linspace(-4*pi, 4*pi, 100);
plot (x, sin (x),'rs-');
xlabel('x-axis')
ylabel('y-axis')
title('Sine function')
axis([-12, 12, -1.5, 1.5])
In [15]:
clear all
figure(2)
x = linspace(-3, 3, 100);
y1 = x;
y2 = x.^3;
y3 = x.^5;
plot(x, y1, 'r')
hold on
plot(x, y2, 'g')
hold on
plot(x, y3, 'b')
axis('equal')
xlabel('x-axis')
ylabel('y-axis')
title('Power Functions Plots')
axis([-3, 3, -3, 3])
legend('y = x','y = x^3','y = x^5')
hold off
In [19]:
clear all
x = linspace(-4*pi, 4*pi, 100);
y1 = sin(x);
y2 = cos(x);
y3 = exp(x);
y4 = cosh(x);
subplot(2,2,1)
plot(x, y1, 'r')
subplot(2,2,2)
plot(x, y2, 'g')
subplot(2,2,3)
plot(x, y3, 'b')
axis([-3, 3, -1, 20])
subplot(2,2,4)
plot(x, y4, 'k')
axis('equal')
axis([-3, 3, 0, 6])
In [20]:
clear all
tx = linspace (-8, 8, 41);
ty = tx;
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
tz = sin (r) ./ r;
In [21]:
mesh (tx, ty, tz);
In [22]:
surf(r)
In [23]:
contourf(xx,yy,r,5)
In [24]:
contour(xx,yy,r,5)
In [17]:
x = -4*pi:0.01:4*pi;
figure(1)
filename = 'gifmovie.gif';
for n = 1:0.1:10
      y = sin(x/n);
      plot(x,y)
      drawnow
      frame = getframe(1);
      im = frame2im(frame);
      [imind,cm] = rgb2ind(im,256);
      if n == 1;
          imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
      else
          imwrite(imind,cm,filename,'gif','WriteMode','append');
      end
end
In [25]:
figure(1)
filename = 'surfmovie.gif';
tx = linspace (-8, 8, 41);
ty = tx;
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;

for n = 1:0.5:20
      tz = sin (r) ./ (n*r);
      mesh (tx, ty, tz);
      axis([-8 8 -8 8 -1 1])
      drawnow
      frame = getframe(1);
      im = frame2im(frame);
      [imind,cm] = rgb2ind(im,256);
      if n == 1;
          imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
      else
          imwrite(imind,cm,filename,'gif','WriteMode','append');
      end
end