常用的 转义字符的网站
https://wenku.baidu.com/view/b906cf6daf1ffc4ffe47ac40.html
http://www.cnblogs.com/hello-Huashan/p/5125578.html
1 Escape characters, including:
'' | Single quotation mark |
%% | Percent character |
\\ | Backslash |
\a | Alarm |
\b | Backspace |
\f | Form feed |
\n | New line |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\xN | Hexadecimal number, N |
\N |
Octal number,
|
2 在 text,legend,plot,sprintf,disp,都要用到
(1)spintf
str1 = 'i love you'; number = 123;
sprintf('%s%d',str1,number)
ans =
i love you123
b = 'feng';
sprintf('%s loves %s',a,b)
(2)fpintf
fprintf 这个语句具体要怎么用呢
可以看这个网站
http://blog.sina.com.cn/s/blog_491b86bf0100xo17.html
这个命令 涉及到很多常用的转换指定符,看这个网站
https://wenku.baidu.com/view/b906cf6daf1ffc4ffe47ac40.html
制表符是\t
回车换行是\n
(在window系统,一般回车换行要用连个符号 \r\n)
'' |
单引号 |
%% |
百分比字符 |
\ \ |
反斜杠 |
\ 1 |
报警book.iLoveMatlab.cn |
\ b |
退格 |
\ f |
换页 |
\n |
新行 |
\ṛ |
回车 |
\t |
水平制表符 |
\ v |
垂直制表 |
\xN |
十六进制数N |
\N |
八进制数N |
数值类型 |
转变 |
详情 |
Integer, signed |
%d or %i |
Base 10 values |
%ld or %li |
64-bit base 10 values | |
%hd or %hi |
16-bit base 10 values | |
Integer, unsigned |
%u |
Base 10 |
%oatlab中文 |
Base 8 (octal)k.iLoveMatlab.cn | |
%x |
Base 16 (hexadecimal), lowercase letters a–f | |
%X |
Same as %x, uppercase letters A–F | |
%lu %lo %lx or %lX |
64-bit values, base 10, 8, or 1 | |
%hu %ho %hx or %hX |
16-bit values, base 10, 8, or 16 | |
浮点数 |
%f |
定点表示法 |
指数符号,如3.141593e +00 | ||
%E |
同为%e,但大写,如3.141593E +00 | |
%g |
更紧凑的%e或%F,没有尾随零 | |
%G |
更紧凑的%E或%F,没有尾随零 | |
%bx or %bX %bo %bu |
双精度十六进制,八进制或十进制值 例如%bx pi 打印为400921fb54442d18皮 | |
%tx or %tX %to %tu |
单精度十六进制,八进制或十进制值 例如:%tx的圆周率打印为40490fdb | |
1.字符 |
%c |
单个字符 |
%s |
字符串中的字符 |
(3)legend plot
legend(string1,string2,string3, ...)分别将字符串1、字符串2、字符串3……标注到图中,每个字符串对应的图标为画图时的图标。
例如:
plot(x,sin(x),'.b',x,cos(x),'+r')
legend('sin','cos')这样可以把"."标识为'sin',把"+"标识为"cos"
还可以用legend(...,'Location',North) 来指定图例标识框的位置
'North' 图例标识放在图顶端
'South' 图例标识放在图底端
'East' 图例标识放在图右方
'West' 图例标识放在图左方
'NorthEast' 图例标识放在图右上方(默认)
'NorthWest 图例标识放在图左上方
'SouthEast' 图例标识放在图右下角
'SouthWest' 图例标识放在图左下角
(以上几个都是将图例标识放在框图内)
'NorthOutside' 图例标识放在图框外侧上方
'SouthOutside' 图例标识放在图框外侧下方
'EastOutside' 图例标识放在图框外侧右方
'WestOutside' 图例标识放在图框外侧左方
'NorthEastOutside' 图例标识放在图框外侧右上方
'NorthWestOutside' 图例标识放在图框外侧左上方
'SouthEastOutside' 图例标识放在图框外侧右下方
'SouthWestOutside' 图例标识放在图框外侧左下方
(以上几个将图例标识放在框图外)
'Best' 图标标识放在图框内不与图冲突的最佳位置
'BestOutside' 图标标识放在图框外使用最小空间的最佳位置
还是用上面的例子
legend('sin','cos','location','northwest')可以将标识框放置在图的左上角。
(4)text
函数text()是创建text图形句柄的低级函数。可用该函数在图形中指定的位置上显示字符串。
用法:
text(x,y,'string')在图形中指定的位置(x,y)上显示字符串string
text(x,y,z,'string') 在三维图形空间中的指定位置(x,y,z)上显示字符串string
text(x,y,z,’string’.'PropertyName',PropertyValue…) 对引号中的文字string定位于用坐标轴指定的位置,且对指定的属性进行设置。表7-6给出文字属性名、含义及属性值。
注意:在同时使用legend()方法和text()方法,插入字符标注时,text()的内容会被legend()的内容所覆盖!(因为text()是低级函数)