For Matlab learning can go through the website octave-online
1. Matrix Construction
1)简单矩阵构造
A=[1,2,3]// 构造一个1x3的矩阵,各元素为1,2,3
或者
A = [1 2 3]//使用空格
B = [1,2,3;7,4,9]//两行三列矩阵B
2)特殊矩阵构造
(1)ones函数
A=ones(n) //构造nxn的全1矩阵
B=ones(m,n)//产生mxn的全1矩阵
(2)zeros
类似的有:
A=zeros(n)//nxn的全0矩阵
B=zeros(m,n)//mxn的全0矩阵
(3)eye
A=eye(n)//nxn的单位矩阵
(4)magic
A=magic(5) 5x5的魔方矩阵
(5)rand // 0~1均匀分布的随机数
A=rand(n)//nxn的随机数矩阵,其中随机数服从0~1的均匀分布
B=rand(m,n)//mxn的随机数矩阵 ,其中随机数服从0~1的均匀分布
(6)randn //均值为0且方差为1的高斯分布随机数
A=randn(n)
B=randn(m,n)// mxn的随机数矩阵,随机数服从均值为0且方差为1的高斯分布
(7)randperm //产生1~n的随机排列
A=randperm(5) //产生1~5的随机排列,如[1 3 5 4 2] 或[5 1 4 2 3]
3)向量构造
(1) a:b //该向量以a为起点,1为步长,所有值属于区间[a,b]
A=1:3 //返回 1 2 3
(2) a:s:b
该向量以a为起点,s为步长,值属于区间[a,b)或[a,b]
(3)使用函数linspace(),logspace().其中linspace()用于创 建制定范围和步长的等距向量
如 A=linspace(-6,6,4) 返回A = -6 -2 2 6
2. Matrix size change
Merge of matrices
1) C=[AB] //Merge in the horizontal direction
2). C=[A;B]//Merge in the vertical direction
Deletion of Matrix Rows and Columns To delete a row or column of a matrix, just assign the row or column to an empty matrix []
A= magic(3);
A(2,:)=[]
3. Matrix element reference (get)
1. 单个元素
若A是二维矩阵, A(i,j)表示第i行第j列的元素,见下面的例子:
A=
8 1 6
3 5 7
4 0 2
A(2,3) 访问元素7
2. 多个元素
A(i,:) // 返回第i 行所有元素
A(:,j) // 返回第j列所有元素
A(i,k1:k2)//返回第i行中的自第k1列到k2列的所有元素
A(k1:k2,j)//返回第j列中的自k1行到k2行的所有元素
A(:,:)//返回矩阵的所有元素
4. Operators
- operator+
- operator-
- Element-wise multiplication.*
- Element right division./
- Element left division.\
-
- Element power.^
- Matrix Multiplication *
- matrix right division /
- Matrix right division \
- Matrix Power^ (Matrix Power)
- Matrix to rank.'
- Matrix conjugate to rank'