MATLAB中输入LateX公式

编写MATLAB的程序时,我们需要将公式标注在 Figure 窗口之上。

Matlab可以在title、xlabel、ylabel、zlabel...上插入LateX公式。

 

1. 在标题中插入LateX公式

figure(1);              % 标题中添加LateX格式公式
x = 0.1:0.1:10;
plot(x, sin(x)./x);
title('$\frac{sin(x)}{x}$','interpreter','latex', 'FontSize', 18);
set(gcf, 'position', [0 0 400 300]);

其中,‘interpreter’ 表示所采用的解释器语法,此时需要设置为'latex'。

'$...$' 是指放在行内的公式;

'\$\$...\$\$是指单独占据一行或几行的公式;

2. 在图例中插入LateX公式

figure(1);              % 图例中添加LateX格式公式
x = 0.1:0.1:10;
plot(x, sin(x)./x);
handle = legend('$\frac{sin(x)}{x}$');
set(handle,'Interpreter','latex', 'FontSize', 18)

3. 在坐标轴中插入LateX公式

figure(1);              % 坐标轴中添加LateX格式公式
alpha = 0.1:0.1:10; beta = sin(x)./x;
plot(alpha, beta);
xlabel('$\alpha$','interpreter','latex', 'FontSize', 18);
ylabel('$\beta$','interpreter','latex', 'FontSize', 18);

4. 一些小问题

4.1 LateX公式在MATLAB中换行

目前我知道的换行方式有两种:

1. 将字符串改写成:{'$...$', '$...$'}

2. 将字符串改写成:['$...$', newline, '$...$']

figure(1);                                 % 新建窗口
set(gcf, 'position', [0 0 700 300]);       % 设定窗口位置和大小
subplot(1,2,1);                            % 1 号子坐标轴
% 换行方式1
title({'$ a_0c(k+n)+a_1c(k+n-1)+...+a_nc(k)$',...        
       '$=b_0r(k+m)+b_1r(k+m-1)+...+b_mr(k)$'},'interpreter','latex');
set(gca,'position',[0.05 0.1 0.4 0.7]);    % 设定坐标轴大小

subplot(1,2,2);                            % 2 号子坐标轴
% 换行方式2
title(['$a_0c(k+n)+a_1c(k+n-1)+...+a_nc(k)$',newline,...    
       '$=b_0r(k+m)+b_1r(k+m-1)+...+b_mr(k)$'] ,'interpreter','latex')
set(gca,'position',[0.6 0.1 0.35 0.7]);    % 设定坐标轴大小

4.2 '$...$' 与 ''\$\$...\$\$' 的区别

'$...$'  会将字符缩小到与设定的字符一样大,即一个公式占一行。

''\$\$...\$\$' 会将每一个字符都设定为预设的大小,一个公式占多行。

figure(1); 
set(gcf, 'position', [0 0 700, 300]);
subplot(1,2,1);
title('$ \frac{sin(x_\alpha)}{x}$','interpreter','latex');
set(gca,'position',[0.05 0.1 0.4 0.7]);
subplot(1,2,2);
title('$$\frac{sin(x_\alpha)}{x}$$' ,'interpreter','latex')
set(gca,'position',[0.6 0.1 0.35 0.7]);

n. 符号对照

修饰符

描述

示例

^{ }

上标

'text^{superscript}'

_{ }

下标

'text_{subscript}'

\bf

粗体

'\bf text'

\it

斜体字体

'\it text'

\sl

斜体字体(通常与斜体字体相同)

'\sl text'

\rm

普通字体

'\rm text'

字符序列

符号

字符序列

符号

字符序列

符号

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ɛ

\Delta

Δ

\spadesuit

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

Θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

\copyright

©

猜你喜欢

转载自blog.csdn.net/XSTX1996/article/details/81627219
今日推荐