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. 有關優先級
- 算數運算符 > 關系運算符 > 邏輯運算符
- 邏輯運算符中,
具有最高優先級,~
和&
優先級相同|
複數及三角運算函數
複數運算函數 | 對應含義 |
| 傳回絕對值或複數的模 |
| 傳回複數的相位,範圍 |
| 傳回複數 |
| 傳回複數的共轭 |
| 傳回複數的實部 |
| 傳回複數的虛部 |
| 判斷矩陣是否含有複數 |
| 平移相位角 |
| 将複數排序為複共轭對組 |
三角運算函數 | 對應含義 |
| 正弦函數 |
| 餘弦函數 |
| 正切函數 |
| 餘切函數 |
| 正割函數 |
|