www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CreatingAPlotExample.m

    %% Creating a Plot
% The |plot| function has different forms, depending on the input
% arguments.
% 
% * If |y| is a vector, |plot(y)| produces a piecewise linear graph of the
% elements of |y| versus the index of the elements of |y|.
% * If you specify two vectors as arguments, |plot(x,y)| produces a graph
% of |y| versus |x|.
% 
% Use the colon operator to create a vector of |x| values ranging from |0|
% to $2\pi$, compute the sine of these values, and plot the result.

x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)

%%
% Add axis labels and a title. The characters |\pi| in the |xlabel| function
% create the symbol  $\pi$. The |FontSize| property in the |title| function
% increases the size the text used for the title.

xlabel('x = 0:2\pi')
ylabel('Sine of x')
title('Plot of the Sine Function','FontSize',12)