2D array to 1D with rows appending after another row

18 vues (au cours des 30 derniers jours)
Ishan Srivastava
Ishan Srivastava le 27 Mar 2023
Commenté : Stephen23 le 27 Mar 2023
how do i go from A =[1 2 3 ; 4 5 6] to A = [1 2 3 4 5 6]
I tried reshape(A,1,6) it gives me [1 4 2 5 3 6]

Réponse acceptée

KSSV
KSSV le 27 Mar 2023
A =[1 2 3 ; 4 5 6] ;
iwant = reshape(A',1,[])
iwant = 1×6
1 2 3 4 5 6
  1 commentaire
Stephen23
Stephen23 le 27 Mar 2023
To make the intent clearer and the code more robust, it is better to use TRANSPOSE:
reshape(A.',1,[])
% ^^

Connectez-vous pour commenter.

Plus de réponses (1)

VBBV
VBBV le 27 Mar 2023
  1 commentaire
VBBV
VBBV le 27 Mar 2023
Transpose the matrix A and take the vertcat

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by