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

    %% Add Title and Axis Labels and Format Ticks
% Plot $\sin(x)$ from $-2\pi$ to $2\pi$ using a function handle. Display
% the grid lines. Then, add a title and label the _x_-axis and _y_-axis.

fplot(@sin,[-2*pi 2*pi])
grid on
title('sin(x) from -2\pi to 2\pi')
xlabel('x');
ylabel('y');

%%
% Use |gca| to access the current axes object. Display tick marks along the
% _x_-axis at intervals of $\pi/2$. Format the _x_-axis tick values by
% setting the |XTick| and |XTickLabel| properties of the axes object.
% Similar properties exist for the _y_-axis.

ax = gca;
ax.XTick = -2*pi:pi/2:2*pi;
ax.XTickLabel = {'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'};