📜  在 MATLAB 中将矩阵转换为行向量

📅  最后修改于: 2022-05-13 01:55:14.463000             🧑  作者: Mango

在 MATLAB 中将矩阵转换为行向量

将矩阵转换为行向量。这种转换可以使用 reshape()函数和 Transpose 操作来完成。此 reshape()函数用于使用给定的大小向量对指定的矩阵进行整形。

句法:

reshape(A, sz)

参数:该函数接受两个参数,如下图所示:

  • A:这是指定的元素矩阵。
  • sz:这是指定大小的向量。

返回值:它返回给定矩阵的行向量。

示例 1

Matlab
% Conversion of a 2D matrix into its
% row vector.
A = [1 2; 3 4]; %Initializing a matrix
  
% Calling the reshape() function
% over the above matrix as its transpose
% and size vector as 1,[]
B = reshape(A.',1,[])


Matlab
%  MATLAB code for Conversion of a 3*3
% matrix into its row vector.
A = [1 2 3; 4 5 6; 7 8 9]; % Initializing a 3*3 matrix
  
% Calling the reshape() function
% over the above matrix as its transpose
% and size vector as 1,[]
B = reshape(A.',1,[])


输出:

示例 2

MATLAB

%  MATLAB code for Conversion of a 3*3
% matrix into its row vector.
A = [1 2 3; 4 5 6; 7 8 9]; % Initializing a 3*3 matrix
  
% Calling the reshape() function
% over the above matrix as its transpose
% and size vector as 1,[]
B = reshape(A.',1,[])

输出: