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

    %% Add Text with Integral Expression to Graph
% Plot $y = x^2\sin(x)$. Draw a
% vertical line at $x = 2$ from the _x_-axis to the plotted line.

% Copyright 2015 The MathWorks, Inc.


x = linspace(0,3);
y = x.^2.*sin(x);
plot(x,y)
line([2,2],[0,2^2*sin(2)])
%% 
% Add text to the graph that contains an integral expression using LaTeX
% markup and add an arrow annotation to the graph. To use LaTeX
% markup, set the |Interpreter| property for the text object to
% |'latex'|.

str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(0.25,2.5,str,'Interpreter','latex')
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4])