π >> x=linspace(,2*pi,3); >> y=sin(x); >> plot(x,y) - - - - - 2 3 4 5 6 7 π
>> x=linspace(,2*pi,3); y=sin(x); z=cos(x); >> plot(x,y,x,z) - - - - - 2 3 4 5 6 7 >> x=linspace(,2*pi,3); y=sin(x); z=cos(x); >> W=[y;z]; % create a matrix of the sin and cosine >> plot(x,w) >>plot(w,x) 7 6 5 4 - - - - 3 2-2 3 4 5 6 7 - - - - -
>> plot(x,y,'g:', x,y,'ko, x,z,'r--', x,z,'c+') - - - - - 2 3 4 5 6 7
>> x=linspace(,2*pi,3); >> y=sin(x); z=cos(x); >> plot(x,y,x,z) >> grid % turn on grid lines >> xlabel('independent Variable X') % x-axis label >> ylabel('dependent Variables Y and Z') % y-axis label >> title('sine and Cosine Curves') % title the plot
>> text(2.5,.7, 'sin(x)') >> gtext('cos(x)') Sine and Cosine Curves sin(x) Dependent Variables Y and Z - - - cos(x) - - 2 3 4 5 6 7 Independent Variable X
>> axis off % turn off the axes >> axis on, grid off Sine and Cosine Curves Sine and Cosine Curves sin(x) sin(x) cos(x) Dependent Variables Y and Z - - cos(x) - - - 2 3 4 5 6 7 Independent Variable X >> axis ij >> axis('square', 'equal') % turn the plot upside down % give axis two commands at once - Sine and Cosine Curves Sine and Cosine Curves - -2 - -.5 Dependent Variables Y and Z - - cos(x) Dependent Variables Y and Z - -.5.5 cos(x) sin(x) sin(x).5 2 2 3 4 5 6 7 Independent Variable X 2 3 4 5 6 Independent Variable X >> axis('xy','normal') % return to the defaults
>> x=linspace(,2*pi,3); y=sin(x); z=cos(x); >> plot(x,y) >> hold on >> plot(x,z,'m') >> hold off - - - - - 2 3 4 5 6 7
>> x=linspace(,2*pi,3); >> y=sin(x); z=cos(x); >> a=2*sin(x).*cos(x); b=sin(x)./(cos(x)+eps); >> subplot(2,2,); plot(x,y), axis([ 2*pi - ]), title('sin(x)') >> subplot(2,2,2); plot(x,z), axis([ 2*pi - ]), title('cos(x)') >> subplot(2,2,3); plot(x,a), axis([ 2*pi - ]), title('2sin(x)cos(x)') >> subplot(2,2,4); plot(x,b), axis([ 2*pi -2 2]), title('sin(x)/cos') >> subplot(,,) % return to a single plot in the figure window
>> orient % what is the current orientation? ans = portrait >> orient landscape % print sideways on the page >> orient tall % stretch to fill the vertical page >> print -djpeg myfig.jpg % make a jpeg file for the figure >> x = linspace(-5,5,5); y = exp(-x.*x); >> plot(x,y); grid >> semilogy(x,y); grid.9.7.5.3. -5-4 -3-2 - 2 3 4 5-2 -4-6 -8 - -2-5 -4-3 -2-2 3 4 5
>> t=:.:2*pi; >> r=sin(2*t).*cos(2*t); >> polar(t,r) >> title('polar Plot of sin(2t)cos(2t)') Polar Plot of 9 sin(2t)cos(2t).5 2.375 6 5 5 3 5 8 2 33 24 27 3 >> x=-2.9::2.9; y=exp(-x.*x); >> bar(x,y) >> stairs(x,y) >> title('bar Chart of a Bell Curve') >> title('stair Chart of a Bell Curve') Bar Chart of a Bell Curve Stair Chart of a Bell Curve.9.9.7.7.5.5.3.3.. -3-2 - 2 3-3 -2-2 3
>> x=-2.9::2.9; % specify 29 bins to use >> y=randn(5,); % create 5 random points >> hist(y,x) % draw the histogram 45 4 35 3 25 2 5 5-3 -2-2 3 >> y=randn(5,); % create some random data >> stem(y,':') % draw a stem plot with dotted line 2.5 2.5.5 -.5 - -.5-2 5 5 2 25 3 35 4 45 5
>> x=:.:2; % create a vector >> y=erf(x); % y is the error function of x >> e=rand(size(x))/; % generate random error values >> errorbar(x,y,e) % create the plot.2 - -.5.5.5 2 2.5 >> z=eig(randn(2,2)); >> compass(z) >> feather(z) 2 9 4.52 6 5 3.384 4 5 2.256 3 3.28 2 8-2 33-2 -3-4 24 27 3-5 5 5 2 25
>> t=randn(,)*pi; >> rose(t) >> title('angle Histogram of Random Angles') Angle Histogram 9 of Random Angles 6 2 6 4 5 2 3 8 2 33 24 27 3 >> x=linspace(-2*pi,2*pi,6); >> y=sin(x).^2./(x+eps); >> plot(x,y) >> title('plot of sin(x)^2/x') >> >> [a,b]=ginput(8); % get up to 8 points >> hold on >> plot(a,b,'co') % plot the collected points >> hold off
Plot of sin(x) 2 /x - - - - -8-6 -4-2 2 4 6 8 >> fplot('sin(x)./x', [-2 2 -.4.2]) - - -2-5 - -5 5 5 2
>> t=(/8:2/8:5/8)'*pi; % column vector with 8 elemets >> x=cos(t); % x coordinate of points on a unit circle >> y=sin(t); % y coordinate of points on a unit circle >> fill(x,y,'r') % a filled red circle using only 8 points >> axis('square') >> text(,,'stop') >> title('red Stop Sign') Red Stop Sign STOP - - - - - - -.5.5
t >> t=:pi/5:*pi; >> plot3(sin(t),cos(t),t) >> title('helix'), xlabel('sin(t)'), ylabel('cos(t)'), zlabel('t') Helix 4 3 2.5 cos(t) -.5 - - -.5 sin(t).5 >> x = :4; y = 2:2:6; >> [X,Y] = meshgrid(x,y) X = 2 3 4 2 3 4 2 3 4
Y = 2 2 2 2 4 4 4 4 6 6 6 6 >> x=-7.5:.5:7.5; >> y=-7.5:.5:7.5; >> [X,Y]=meshgrid(x,y); >> R=sqrt(X.^2+Y.^2)+eps; % distance from the origin (,) >> Z=sin(R)./R; % calculate sin(r)/r >> mesh(x,y,z) >> surf(x,y,z)
>> mesh(peaks) >> title('mesh Plot of the Peaks Function') >> [x,y,z]=peaks; >> contour(x,y,z,2) >> contour3(x,y,z,2) % generate 2 2-D contours % the same contour plot in 3-D 3 2 5-5 - - -2-3 -3-2 - 2 3 2-2 -3-2 - 2 3
>> [x,y,z]=peaks(2); >> [x,y,z]=peaks; >> pcolor(x,y,z) >> pcolor(z);colormap(hot);shading flat >> colormap default, shading faceted >> hold on, contour(z,2,'k'), hold off
>> subplot(2,2,); mesh(peaks(2)); >> subplot(2,2,2); mesh(peaks(2)); view(,); title('view(,)') >> subplot(2,2,3); mesh(peaks(2)); view(-9,); title('view(-9,)') >> subplot(2,2,4); mesh(peaks(2)); view(,9); title('view(,9)') >> view([-7-9 7]) % view through (-7,-9,7) to the origin >> [az,el]=view % find the azimuth and elevation az = -37.875 el = 3.5475
>> mesh(peaks(2)+7) % coarse (2) mesh, shifted up >> hold on; pcolor(peaks(2)); hold off >> hidden on >> hidden off >> title('mesh with Hidden On') >> title('mesh with Hidden Off') >> meshc(peaks); >> meshz(peaks)
>> colormap(gray) >> surfl(peaks), shading interp >> title('surfl Plot of Peaks with Default Lighting')
>> fill3(rand(3,4),rand(3,4),rand(3,4),rand(3,4)).5 >> P = [- - ; - 2; 3; 4]; >> X=P(:,); Y=P(:,2); Z=P(:,3); C=P(:,4); >> T = [ 2 3; 2 4; 2 3 4; 3 4]'; >> fill3(x(t), Y(T), Z(T), C(T)).5.5 -.5.5 - - -.5
>> mesh(peaks) >> colormap(hsv) >> colorbar
π π
θ θ θ θ π π π π cos π cos sin sin θ θ θ θ θ θ