Array Operations
MATLAB 中有两种 Matlab Arithmetic Operations: Matlab Matrix Operations 和 array operations.
Array operations 就是点运算, element-wise 运算, 区别于 Matlab Matrix Operations 的矩阵运算.
MATLAB 中的数学运算函数, 除了是明确的矩阵运算, 主要默认是 array operations, 如函数 sin, sqrt, exp, log, 而对应的 Matlab Matrix Operations 一般名字有 m 加以区别, 如 sqrtm, expm, logm, mtimes, mpower.
Operators
基本的双目或单目 array operations 都能通过运算符实现.
| Operator | Equivalent Function |
|---|---|
+ | plus |
- | minus |
.* | times |
./ | rdivide |
.\ | ldivide |
.^ | power |
说明
-
以上所有 array operations 都是 binary 运算, 运算对象尺寸需满足 Matlab Compatible Array Sizes, 具体的运算过程为先将两个运算扩展为同尺寸数组, 然后再同索引元素逐元素运算
-
如
>> a = [1 2 3]; b = [1 2 3]'; >> a .* b % 实际等于 repmat(a,3,1) .* repmat(b,1,3) ans = 1 2 3 2 4 6 3 6 9
-
-
因为加减法 array operations 与矩阵运算一致, 故没有区别
-
A ./ B是以 A 中元素为分子, B 中元素为分母的除法 -
A .\ B是以 A 中元素为分母, B 中元素为分子的除法