如何在MATLAB中实现各种特殊上标? | 您所在的位置:网站首页 › 在电脑上怎么打出横线写上字母 › 如何在MATLAB中实现各种特殊上标? |
MATLAB作为最强大的数学工具之一,其应用及其广泛,对初学者来说经常会遇到一些问题。最近遇到同学提出的字母上标问题,要求在字母正上方标注横线或者尖角,在数学中这是常见的标识方法,但在MATLAB中有其特殊的表示方法。本人在学习中也搜索相关的表达方式,发现大多数表述不完整,或者实现方式不对,因此抽时间整理并编写代码,将大多数上下标的实现方式以代码的形式展示出来,供大家学习交流。 1、上下标示例展示: 本文只针对特殊上标情况,上下角标可由符号“^”或者“_”实现,故不在本文讨论范围之内,特殊上标的示例如下图所示。 图示中所有上标标识均可由代码实现。其中绿色部分是常见错误的表示,因为绿色的标识只在第一个字符的正上方标注,而正确的标识要求标注符号均体现在字符的正上方。红色部分为正确示范,供读者学习参考。 2、应用举例及代码实现 完整代码 clear;clc;close all; figure('Position',[300 100 800 600],'Color','w'); title('MATLAB中特殊上标实现演示','FontSize',20,'color','b'); xlim([0 7]); ylim([-0.5 1]); axis off; %用0.5作底是为了方便区别上标位置,有些上标可能只在第一个字符上面,而不是正中间 %text前两个数字代表在图中的位置 text(4,0.8,'$\overline{0.5}$','interpreter','latex','FontSize', 24,'Color','r');%正确上划线 text(5,0.8,'$\bar{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确上划线 text(5,0.6,'\~{0.5}','interpreter','latex','FontSize', 24,'Color','g'); %错误~上标 text(4,0.6,'$\tilde{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确~上标 text(3,0.6,'$\widetilde{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确宽~上标 text(4,0,'$\dot{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确一阶导数 text(5,0,'\.{0.5}','interpreter','latex','FontSize', 24,'Color','g'); %错误一阶导数 text(3,0,'$\ddot{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确二阶导数 text(5,0.4,'\^{0.5}','interpreter','latex','FontSize', 24,'Color','g'); %错误^上标 text(4,0.4,'$\hat{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确^上标 text(1,0.4,'$\widehat{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %正确宽^上标 text(5,0.2,'\t{0.5}','interpreter','latex','FontSize', 24,'Color','g'); %错误弧线上标 text(2,0.8,'$\sum\limits_a^b$','interpreter','latex','FontSize', 24,'Color','r'); %求和 text(3,0.4,'$\vec{0.5}$','interpreter','latex','FontSize', 24,'Color','r'); %上标箭头 %以下代码通用性较强,只需修改$\stackrel{F}{\longrightarrow}$蓝色标记的符号,即可实现大多数字符的上标,%字符见参考文献[4],以下为示例: text(1,0.2,'$X\stackrel{F}{\longrightarrow}Y$','interpreter','latex','FontSize',24,'Color','r'); text(4,0.2,'$\stackrel{F}{\longrightarrow}$','interpreter','latex','FontSize', 24,'Color','r'); text(3,0.2,'$\stackrel{\rightharpoonup}{0.5}$','interpreter','latex','FontSize',24,'Color','r'); text(1,-.2,'$\stackrel{\longleftarrow}{0.5}$','interpreter','latex','FontSize',24,'Color','r'); text(2,-0.2,'$\stackrel{\frown}{0.5}$','interpreter','latex','FontSize', 24,'Color','r');最后强调一个通用性较强的代码,在LATEX下只需修改$\stackrel{F}{\longrightarrow}$蓝色标记的符号,即可实现大多数字符的上标,可以尝试将不同的上标添加进去。 感谢雾里看花给公众号投稿,欢迎更多爱好、喜欢matlab编程的朋友来稿,在公众号回复“投稿”了解投稿详情。 参考资料: [1] https://blog.csdn.net/zhoutianzi12/article/details/94158455 [2] https://blog.csdn.net/liyuanbhu/article/details/51473886 [3] https://zhidao.baidu.com/question/1052703552360580659.html [4] https://blog.csdn.net/J__Max/article/details/86549124 |
CopyRight 2018-2019 实验室设备网 版权所有 |