在 MATLAB 中将数组转换为列向量
将数组转换为列向量。可以使用 (:) 操作完成此转换。 A(:) 将 A 的所有元素重塑为单个列向量。如果 A 已经是列向量,则这不起作用。
示例 1
Matlab
% MATLAB code for Conversion of an array
% into a column vector
a = [2 4 6 8] % Initializing an array of some elements
% Converting above array into a column
% vector using a(:) operation
Column_Vector = a(:)
Matlab
% MATLAB code for Conversion of an
% array matrix into a column vector.
a = [1 2; 3 4; 5 6] % Initializing an array
% Converting above array matrix into a column
% vector matrix using a(:) operation
Column_Vector_matrix = a(:)
输出:
示例 2
MATLAB
% MATLAB code for Conversion of an
% array matrix into a column vector.
a = [1 2; 3 4; 5 6] % Initializing an array
% Converting above array matrix into a column
% vector matrix using a(:) operation
Column_Vector_matrix = a(:)
输出: