将MATLAB当做计算器使用
MATLAB Programming Modes
使用MATLAB的两种方式:
- Command line (in command window)
- Scripts (.m files)
MATLAB as A Calculator
operators: + - * / ^
优先级:() > ^ > * / > + -
ln -> log e -> exp(1)
Elementry Math Function(基本数学函数)
......
Embedding Function(嵌套函数)
......
Variable(变数)
MATLAB中变数不需要宣告
变数 = 变数/常数
Numeric Variable (Data)Type
默认类型为double
Special Variable and Constants
>> iskeyword
ans i j inf eps NaN pi ......
Matlab Calling Priority
>> cos = 'This string.';
>> cos(8)
>> clear cos
Numeric Display "Format"
short
long
shortE
longE
rat
Command Line Terminal
>> b = 10; % 分号表示不显示运算结果
PgUp -> display previous commands
Some Functions
clc
clear
who
whos
矩阵操作
Array(Vector and Matrix)
>> a = [1 2 3 4]
>> b = [1;2;3;4]
Array Indexing
1.序号索引
>> A(8)
>> A([1 3 5])
>> A([1 3;1 3])
2.行,列索引
>> A(3,2)
>>A([1 3],[1 3])
Replacing Entries
>> A(1,2) = 76;
Colon Operator
>> A = [1:100];
>> A = [1:2:99]; % 步长
>> A(3,:) = [ ]; %第三行置空
调用函数或对变量进行索引时,使用圆括号
Array Concatenation
>> A = [B C];
>> A = [B;C];
Array Manipulation(矩阵的运算)
>> A = [1 2 3;4 5 4;9 8 7];
>> B = [3 3 3;2 4 9;1 3 1];
>> y1 = A+B
>> y2 = A*B
>> y3 = A.*B
>> y4 = A/B
>> y5 = A./B
>> x1 = A+a
>> x2 = A/a
>> x3 = A./a
>> x4 = A^a
>> x5 = A.^a
>> C = A'
Some Special Matrix
eye(n) zeros(n1,n2) ones(n1,n2) diag() % diag([1 2 3])
Some Matrix Related Functions
>> A = [1 2 3;0 5 6; 7 0 9]
>> max(A) % 7 5 9 按每一列做运算
>> max(max(A)) % 矩阵的最大值
>> min(A)
>> sum(A)
>> mean(A)
>> sort(A)
>> sortrows(A)
>> size(A)
>> length(A)
>> find(A) % find(A == 5)