2.1 Variables
1.变量在执前不需要声明。
2.大小写的变量不一样。
3.变量不能以数字开头。
2.2 Special Variables
- ans
- i,j
- eps(代表极小数)
- NaN(Not a Number,例如x=Inf/Inf)
- Pi
1.不要用keyword当作你的function name
答案:1. d.
2.添加分号(;)就不会显示运算结果
Some Functions
·clc:clear command window display
·clear:remove all variables in the workspace
·who:variables in the workspace
·whos: variable information of the workspace
Matlab 擅长矩阵的运算
2.3 Array (Vector and Matrix)
Row vector:
>> a = [1 2 3 4]
Column vector:
>>b = [1; 2 ; 3 ;4]
2.4 Array Indexing
A(8) >>按照列来数,第8个
A([1 3 5])>>由A(1) A(3) A(5)组成的矩阵
A([1 3 5])= 1 31 17
A[(1 3;1 3])>>由A(1) A(3) A(1) A(3)组成的矩阵
1 31
- 3
A([1 3],[1 3])
2.5 Colon Operater(:等差)
>>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.0000 2.0000 3.0000 4.0000 5.0000
2.0000 5.0000 8.0000 11.0000 14.0000
-2.0000 -1.5000 -1.0000 -0.5000 0
>> str = 'a':2:'z'
'acegikmoqsuwy'
2.6 Indexing Using Colon Operator
>>A(3,:) = []
2.7 Array Concatenation
2.8 Array Manipulation
2.9 Some Special Matrix
eye(n): n×n的单位矩阵
zeros(n1,n2):n1×n2的0矩阵
ones(n1,n2): n1×n2的1矩阵
diag():取出对角线上面的元素
2.10 Some Matrix Related Functions