how to convert 2-D array to 1-D array

4 次查看(过去 30 天)
how to convert 2-D array of dimension n*m to 1-D array with length (n*m) if a=[1 2 3;4 5 6;7 8 9] i want a = [1 2 3 4 5 6 7 8 9] so how

采纳的回答

Guillaume
Guillaume 2018-4-17

transpose then reshape

a = reshape(a.', 1, [])

更多回答(1 个)

Bosong Lin
Bosong Lin 2018-4-17
Hey,
Try this. A = [1,2;3,4]; A = A(:);
  1 个评论
Guillaume
Guillaume 2018-4-17
Ashraf wants the reshaping done by row, this would do it by column which is not what is asked. It produces [1;3;2;4] instead of [1,2,3,4]

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by