gno*_*ice 64
您可以通过几种不同的方法将矩阵折叠为矢量,具体取决于您希望矩阵的内容如何填充该矢量.这里有两个例子,一个使用函数reshape(在第一次转置矩阵之后),另一个使用冒号语法 (:):
>> M = [1 2 3; 4 5 6; 7 8 9]; % Sample matrix
>> vector = reshape(M.', [], 1) % Collect the row contents into a column vector
vector =
1
2
3
4
5
6
7
8
9
>> vector = M(:) % Collect the column contents into a column vector
vector =
1
4
7
2
5
8
3
6
9
Run Code Online (Sandbox Code Playgroud)