Matlab基础(1)——基础知识
文章目录
- Matlab基础(1)——基础知识
- 常量
- 数据类型
- 运算符
- 复数及三角运算函数
常量
常量名称 | 对应含义 |
| 圆周率 |
| 浮点相对精度,常用于防止0出现在分母上 |
( ) | 无穷大,如 |
( ) | 不定值,如、、 |
( ) | 复数中的虚数单位 |
| 最小正浮点数 |
| 最大正浮点数 |
ps. 常量可以被赋值,使用命令
clear
+
变量名
或重启Matlab可以将常量恢复初始值。
数据类型
整型 | 含义 | 占用空间 |
| 字符型 | 1字节 |
| 无符号字符型 | 1字节 |
| 短整型 | 2字节 |
| 无符号短整型 | 2字节 |
| 有符号整型 | 4字节 |
| 无符号整型 | 4字节 |
| 长整型 | 4字节 |
| 无符号长整型 | 4字节 |
浮点型:
- 十进制数形式:由数字和小数点组成
- 指数形式:一般形式为
,其中aEn
为10进制数,a
为10进制整数,表示n
- 可以分为两类:单精度型和双精度型
- 单精度
,占4字节,数值范围,最多7位有效数字float
- 双精度
,占8字节,数值范围,最多16位有效数字double
ps. 使用命令
format
可以控制命令行的输出格式,参考
help format
类型转换
nu = 123;
st = num2str(nu); % '123'
遇到不熟悉的类型转换时,可以使用
lookfor
指令查找相关函数:
>> lookfor num2
num2cell - Convert numeric array into cell array.
num2hex - Convert singles and doubles to IEEE hexadecimal string format
num2str - Convert numbers to character representation
num2ruler - Convert numeric array to ruler-appropriate array datatype
enum2val - Converts an enumerated string to its numerical equivalent.
num2cell - Convert numeric codistributed array into cell array
num2str - overloaded for gpuArrays
num2mstr - Convert number to string in maximum precision.
iptnum2ordinal - Convert positive integer to ordinal string.
num2ordinal - Convert positive integer to ordinal character vector.
signal_num2str - Convert the number to a string.
num2goid - Converts numbers to Gene Ontology IDs.
num2str - Convert numbers to character representation
defnum2 - Sets Default channel names
num2deriv - Numeric two-point network derivative function.
num2base - Convert stored integers to strings
num2sdec - Convert stored integers of array of fi objects to signed decimal representation
num2fixpt - Quantize a value using a Fixed-Point Designer representation.
num2alphaheaders - Generate Alpha headers from a number (usually column).
>>
运算符
算数运算符 | 定义 |
| 算数加 |
| 算数减 |
| 算数乘 |
| 点乘 |
| 算数乘方 |
| 点乘方 |
| 算数左除 |
| 点左除 |
| 算数右除 |
| 点右除 |
| 矩阵共轭转置 |
| 矩阵转置,不求共轭 |
其中:
- 左除
表示,右除a\b
表示a/b
-
表示矩阵乘法,要求矩阵的第二维度与矩阵的第一维度相等,A*B
表示矩阵按位乘法,要求矩阵和矩阵的形状相同,对乘方具有一致要求A.*B
-
要求矩阵和矩阵的形状相同,对算数减有一致要求A+B
-
表示对矩阵中的每个元素都,对其他算数运算有一致要求A+a
关系运算符 | 定义 |
| 等于 |
| 不等于 |
( ) | 大于/小于 |
( ) | 大于等于/小于等于 |
逻辑运算符 | 定义 |
| 逻辑与 |
` | ` |
| 逻辑非 |
| 逻辑异或 |
| 有非零元素则为真 |
| 所有元素均非零则为真 |
ps. 有关优先级
- 算数运算符 > 关系运算符 > 逻辑运算符
- 逻辑运算符中,
具有最高优先级,~
和&
优先级相同|
复数及三角运算函数
复数运算函数 | 对应含义 |
| 返回绝对值或复数的模 |
| 返回复数的相位,范围 |
| 返回复数 |
| 返回复数的共轭 |
| 返回复数的实部 |
| 返回复数的虚部 |
| 判断矩阵是否含有复数 |
| 平移相位角 |
| 将复数排序为复共轭对组 |
三角运算函数 | 对应含义 |
| 正弦函数 |
| 余弦函数 |
| 正切函数 |
| 余切函数 |
| 正割函数 |
|