利用MATLAB编程绘图时,有时需要在标题、坐标轴中添加数学公式、希腊字母等特殊字符,此时利用LaTex语句即可完美插入相关内容,现将部分LaTex语法以及常用特殊符号汇总如下:
一、对MATLAB生成的图形标注
MATLAB图形中title、xlabel、ylabel、zlable、textbox、legend等的Interpreter属性包括latex、tex和none,其中默认为tex。需要使用LaTex时,将Interpreter属性设置为latex。在MATLAB中使用LaTex的格式有三种:
1、\( Latex Command \)
2、$ LaTex Command $
3、$$ LaTex Command $$
案例:
x = 0:0.1:2*pi;
y1 = sin(x);
y2 = cos(x)*0.5;
plot(x,y1,x,y2);
legend({'y = sin(x)','$$ y = \frac{cos(x)}{2}$$'},'interpreter','latex');
set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置
二、具体公式编辑
2.1 字符位置设置
序号 | 需求 | 函数字符结构 | 示例 |
---|---|---|---|
1 | 上角标 | ^{ } | title( '$ a^2 + b^2 = c^2 $ ', 'interpreter', 'latex') |
2 | 下角标 | _{ } | title( '$ a_2 + b_2 = c_{bd} $', 'interpreter', 'latex' ) |
2.2 字符字体设置
1、字体加粗:\bf{ x }
2、字体倾斜1:\it{ x }
3、字体倾斜2:\sl{ x }
4、正常字体:\rm{ x }
5、设置字体名:\fontname{ 字体名 }
6、设置字体大小:\fontsize{ 字体大小 }
7、设置字体颜色:\color{ red }
可用颜色包括:red、green、yellow、magenta、blue、black、white、cyan、gray、barkGreen、orange、lightblue。
% Demo
x = -5:0.05:5;
y = x.^3 + 1;
plot(x,y);
grid on;
title('$y = x^2 + a_0 + \bf{A_1} + \it{A_2} + \sl{A_3}$','interpreter','latex');
set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置
2.3 具体公式编辑
1、求和运算:\sum_{ i=1 }^{ n }
2、积分运算:\int_{ x_1 }^{ x_2 }
3、极限运算:
$$\lim_{n \rightarrow \infty}$$ % n趋于无穷符号在lim正下方
$\lim_{n \rightarrow \infty}$ % n趋于无穷符号在lim右下角
% 区别是符号在正下方左右各用了2个$符号,符号在右下角左右各用了1个$符号
4、分式运算:\frac{ x^2 + y^2 } { x+y+z }
% Demo
x = -5:0.05:5;
y1 = x.^3 + 1;
y2 = x.^3 ;
plot(x,y1,x,y2);
grid on;
title('$ y = \sum_{i=1}^{n}x_{i} + \frac{1}{2} + \int_{0}^{5}x$','interpreter','latex');
legend({'$$\lim_{n \rightarrow \ infty}$$','$ \lim_{n \rightarrow \ infty} $'},'interpreter','latex')
set(gcf,'unit','centimeters','Position',[4 2 12 5.5]);% 设置图片大小与位置
5、根式运算:\sqrt{ x^2 + y^2 }
6、上划线:\overline{ x }
7、下划线:\underline{ x }
8、卧式花括号:\overbrace{ x+y+z }
% Demo
x = -5:0.05:5;
y = x.^3 + 1;
plot(x,y);
grid on;
title('$y = x^2 + \overline{x} + \underline{x} + \sqrt{x} + \overbrace{x+y}$','interpreter','latex');
set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置
9、仰视花括号:\underbrace{ a+b+c }
10、戴帽命令:\hat{ x }、\check{ x }、\breve{ x }、\widehat{ A+B }、\widetilde{ a+b }、\vec{ x }、\vec{ \imath }
11、堆砌命令:\stackrel{ \rm def }{ = } f(x)
12、省略号:\cdots、\ldots、\vdots、\ddots
% Demo
x = -5:0.05:5;
y = x.^3 + 1;
plot(x,y);
grid on;
title('$\underbrace{x+y} + \hat{x} + \check{x} + \breve{x} + \vec{\imath} + y \stackrel{\rm def}{=} + \cdots + \ldots +\vdots +\ddots$ ','interpreter','latex');
set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置
三、特殊符号汇总
序号 | 函数字符 | 表征符号 | 函数字符 | 表征符号 | 函数字符 | 表征符号 |
---|---|---|---|---|---|---|
1 |
| α |
| υ |
| ~ |
2 |
| ∠ |
| Φ |
| ≤ |
3 |
|
|
| χ |
| ∞ |
4 |
| β |
| ψ |
| ♣ |
5 |
| γ |
| ω |
| ♦ |
6 |
| δ |
| Γ |
| ♥ |
7 |
| ɛ |
| Δ |
| ♠ |
9 |
| ζ |
| Θ |
| ↔ |
10 |
| η |
| Λ |
| ← |
11 |
| Θ |
| Ξ |
| ⇐ |
12 |
| ϑ |
| Π |
| ↑ |
13 |
| ι |
| Σ |
| → |
14 |
| κ |
| ϒ |
| ⇒ |
15 |
| λ |
| Φ |
| ↓ |
16 |
| µ |
| Ψ |
| º |
17 |
| ν |
| Ω |
| ± |
18 |
| ξ |
| ∀ |
| ≥ |
19 |
| π |
| ∃ |
| ∝ |
20 |
| ρ |
| ∍ |
| ∂ |
21 |
| σ |
| ≅ |
| • |
22 |
| ς |
| ≈ |
| ÷ |
23 |
| τ |
| ℜ |
| ≠ |
24 |
| ≡ |
| ⊕ |
| ℵ |
25 |
| ℑ |
| ∪ |
| ℘ |
26 |
| ⊗ |
| ⊆ |
| ∅ |
27 |
| ∩ |
| ∈ |
| ⊇ |
28 |
| ⊃ |
| ⌈ |
| ⊂ |
29 |
| ∫ | \ | · |
| ο |
30 |
| ⌋ | \ | ¬ |
| ∇ |
31 | \ | ⌊ | \ | x | \ | ... |
32 |
| ⊥ | \ | √ | \ | ´ |
33 | \ | ∧ | \ | ϖ | \0 | ∅ |
34 | \ | ⌉ | \ | 〉 | \ | | |
35 | \ | ∨ | \ | 〈 | \ | © |