如何在matlab中的xlabel,ylabel,legend和text函数中使用latex

如题所述

clc;clear
x=0:0.1:pi;
plot(x,exp(x),'r-.')
xlabel('$$x$$','interpreter','latex','fontsize',22,'color','r')
h=legend('$$y={e^x}$$');
set(h,'interpreter','latex','fontsize',20)

结果:

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-14

首先要掌握一些latex语法,包括常用数学符号、希腊字母、分式等的书写方法
其次字符串中的数学公式要用一对'$$'包括起来,最后注意设置参数Interpreter为Latex。

看下面的例子:

x = linspace(-3,3);
y = sin(x);
plot(x,y)

y0 = x;
hold on
plot(x,y0)

y1 = x - x.^3/6;
plot(x,y1)
hold off

str = '$$\sin(x) = \sum_{n=0}^{\infty}{\frac{(-1)^n x^{2n+1}}{(2n+1)!}}$$';
text(-2,1,str,'Interpreter','latex')

h=legend('$$\sin(x) $$', '$$ y=x $$', '$$ y=x-{\frac{x^3}{6}} $$');
set(h,'Interpreter','latex');

xlabel({'$\int_0^x\!\int_y dF(u,v)$'},'Interpreter','latex');
title('$$ \sqrt{x^2+y^2}$$','Interpreter','Latex');

本回答被网友采纳
相似回答