www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/LinePlotsGSExample.m
%% Line Plots %% % To create two-dimensional line plots, use the |plot| function. For % example, plot the value of the sine function from 0 to $2\pi$: % Copyright 2015 The MathWorks, Inc. x = 0:pi/100:2*pi; y = sin(x); plot(x,y) %% % You can label the axes and add a title. xlabel('x') ylabel('sin(x)') title('Plot of the Sine Function') %% % By adding a third input argument to the |plot| function, you can plot the % same variables using a red dashed line. plot(x,y,'r--') %% % The |'r--'| string is a _line specification_. Each specification can % include characters for the line color, style, and marker. A marker is a % symbol that appears at each plotted data point, such as a |+|, |o|, or % |*|. For example, |'g:*'| requests a dotted green line with |*| markers. % % Notice that the titles and labels that you defined for the first plot are % no longer in the current _figure_ window. By default, MATLAB(R) clears % the figure each time you call a plotting function, resetting the axes and % other elements to prepare the new plot. %% % To add plots to an existing figure, use |hold|. x = 0:pi/100:2*pi; y = sin(x); plot(x,y) hold on y2 = cos(x); plot(x,y2,':') legend('sin','cos') %% % Until you use |hold off| or close the window, all plots appear in the % current figure window.