www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/AddTextArrowsToDataPointsOnGraphExample.m
%% Add Text to Three Data Points on Graph % This example shows how to add text descriptions with arrows that point to % three data points on a graph. % % Use the |linspace| function to create |t| as a vector of 50 values between % 0 and $2\pi$. Create |y| as sine values. Plot the data. t = linspace(0,2*pi,50); y = sin(t); plot(t,y) %% % Use the |text| function to add a text description to the graph at the % point $(\pi,\sin(\pi))$. The first two input arguments to this function % specify the text position. The third argument specifies the text. Display % an arrow pointing to the left by including the TeX markup |\leftarrow| in the % text. Use the TeX markup |\pi| for the Greek letter $\pi$. x1 = pi; y1 = sin(pi); txt1 = '\leftarrow sin(\pi) = 0'; text(x1,y1,txt1) %% % Add text descriptions to two more data points on the graph. By default, % the data point is to the left of the text. To show the data point to the % right of the text, specify the |HorizontalAlignment| property as % |'right'|. Use the TeX markup |\rightarrow| to diplay an arrow pointing % to the right. x2 = 3*pi/4; y2 = sin(3*pi/4); txt2 = '\leftarrow sin(3\pi/4) = 0.71'; text(x2,y2,txt2) x3 = 5*pi/4; y3 = sin(5*pi/4); txt3 = 'sin(5\pi/4) = -0.71 \rightarrow'; text(x3,y3,txt3,'HorizontalAlignment','right')