天天看点

Matlab基础(1)——基础知识

Matlab基础(1)——基础知识

文章目录

  • ​​Matlab基础(1)——基础知识​​
  • ​​常量​​
  • ​​数据类型​​
  • ​​运算符​​
  • ​​复数及三角运算函数​​

常量

常量名称 对应含义

​pi​

圆周率

​eps​

浮点相对精度,常用于防止0出现在分母上

​inf​

​​(​

​Inf​

​)
无穷大,如

​NaN​

​​(​

​nan​

​)
不定值,如、、

​i​

​​(​

​j​

​)
复数中的虚数单位

​realmin​

最小正浮点数

​realmax​

最大正浮点数

ps. 常量可以被赋值,使用命令​

​clear​

​​+​

​变量名​

​或重启Matlab可以将常量恢复初始值。

数据类型

整型 含义 占用空间

​char​

字符型 1字节

​unsigned char​

无符号字符型 1字节

​short​

短整型 2字节

​unsigned short​

无符号短整型 2字节

​int​

有符号整型 4字节

​unsigned int​

无符号整型 4字节

​long​

长整型 4字节

​unsigned long​

无符号长整型 4字节

浮点型:

  • 十进制数形式:由数字和小数点组成
  • 指数形式:一般形式为​

    ​aEn​

    ​​,其中​

    ​a​

    ​​为10进制数,​

    ​n​

    ​​为10进制整数,表示
  • 可以分为两类:单精度型和双精度型
  • 单精度​

    ​float​

    ​​,占4字节,数值范围,最多7位有效数字
  • 双精度​

    ​double​

    ​​,占8字节,数值范围,最多16位有效数字

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​

    ​​表示对矩阵中的每个元素都,对其他算数运算有一致要求
关系运算符 定义

​==​

等于

​~=​

不等于

​>​

​​(​

​<​

​)
大于/小于

​>=​

​​(​

​<=​

​)
大于等于/小于等于
逻辑运算符 定义

​&​

逻辑与
` `

​~​

逻辑非

​xor​

逻辑异或

​any​

有非零元素则为真

​all​

所有元素均非零则为真

ps. 有关优先级

  • 算数运算符 > 关系运算符 > 逻辑运算符
  • 逻辑运算符中,​

    ​~​

    ​​具有最高优先级,​

    ​&​

    ​​和​

    ​|​

    ​优先级相同

复数及三角运算函数

复数运算函数 对应含义

​abs(z)​

返回绝对值或复数的模

​theta=angle(z)​

返回复数的相位,范围

​z=complex(a,b)​

返回复数

​conj(z)​

返回复数的共轭

​a=real(z)​

返回复数的实部

​b=imag(z)​

返回复数的虚部

​isreal(x)​

判断矩阵是否含有复数

​unwrap​

平移相位角

​cplxpair​

将复数排序为复共轭对组
三角运算函数 对应含义

​sin()​

正弦函数

​cos()​

余弦函数

​tan()​

正切函数

​cot()​

余切函数

​sec()​

正割函数

​csc()​

继续阅读