matlab-變量類型-數組-矩陣
1 變量類型
1.1基本
1.2 特殊變量
- ans
- •i,j: complex number
- •Inf: 無窮大
- •eps: 2.2204e-016
- •NaN: not a number
- •pi:pai
註意:關鍵字是可以做變量的
1.3 numeric display format
1.4 some useful functions
- •clc: clear command windowdisplay
- •clear: remove all variables in the workspace
- •who: variables in the workspace
- •whos: variable information of the workspace
2 數組
1.1 定義
row vector:
>> a = [1 2 3 4]
column vector:
>> b= [1; 2; 3; 4]
1.2 數組下標
Select a certain subset of elements inside a matrix
•What’s the answer from MATLAB after typing?
9
>> A([1 3 5])
1 31 17
>> A([1 3; 1 3])
>> A(3,2)
2
>> A([1 3], [1 3])
1.3 Colon Operator
•Want to create a long array:A= [12 3 … 100]
•Creates vectors or arrays, and specify for iterations
•Syntax:
•What’s the answer from MATLAB after typing?
>> B = 1:5
1 2 3 4 5
>> B = 1:2:5
1 3 5
>> B = [1:5; 2:3:15; -2:0.5:0]
1 2 3 4 5
2 5 8 11 13
-2 -1.5 -1 -0.5 0
>>str= ‘a‘:2:‘z‘
a b c ... z
1.4 Array Concatenation
1.5 Array Manipulation
數組運算
>> x1=A+a
每個都加2
>> y1=A+B
對應位想加
>> x2=A/a
每位都除以a
>> y2=A*B
>> x3=A./a
對應位相乘a
>> y3=A.*B
對應位相乘
>> x4=A^a
a個A相乘
>> y5=A./B
對應位想除
>>C=A‘
轉置矩陣
Some Special Matrix
一些特殊的矩陣
Matrix Related Functions
一些矩陣函數
>>max(A)
>>max(max((A))
結果是 9
也就是對上面的[9 8 7 ] 中取最大的
>>sort(A)
從小到大 按照列排序
>>sortrows(A)
從小到大 按照行排序
>> min(A)
參照最大
>> size(A)
結果是 3 3 表示有3行3列
>> sum(A)
對每列求和
matlab-變量類型-數組-矩陣