Open In App

Turn a Matrix into a Row Vector in MATLAB

Conversion of a Matrix into a Row Vector. This conversion can be done using reshape() function along with the Transpose operation. This reshape() function is used to reshape the specified matrix using the given size vector.

Syntax:

reshape(A, sz)

Parameters: This function accepts two parameters, which are illustrated below:



Return Value: It returns the row vector of a given matrix.

Example 1 






% 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,[])

Output:

Example 2




%  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,[])

Output:

Article Tags :