How can i reorder NxM matrix into a 1D array

1 次查看(过去 30 天)
I am looking to take a sample matrix below. The matrix will be large and looking for fast and non looping solution. Thank you.
a=[1 2 3;4 5 6;7 8 9];
reshape it into:
b=[7 8 9 4 5 6 1 2 3];
  1 个评论
Matthew
Matthew 2018-6-12
No the matrix is not always 3 rows. It will likely be much more in both rows and columns.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2018-6-12
Using the reshape (link) function:
b = reshape(a([3 2 1],:)', 1, [])
b =
7 8 9 4 5 6 1 2 3

更多回答(1 个)

Alfonso
Alfonso 2018-6-12
Without looping you can do:
b = [a(end,:), a(end-1,:), a(end-2,:)]; % 1D array
b =
7 8 9 4 5 6 1 2 3
You can repeat the iterations as many rows you have: [a(end-1,:), ... ,a(end-50,:)]

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by