How do I turn a nxm matrix into a single array?
10 次查看(过去 30 天)
显示 更早的评论
hi Matlabers,
say I have a matrix
[1 2 3 4;5 6 7 8;9 10 11 12; 13 14 15 16]
how can I turn this matrix so all the rows are combined into one. one after the other.
result
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]?
thanks in advance. cheers SN
0 个评论
采纳的回答
Sachin Ganjare
2012-10-17
编辑:Sachin Ganjare
2012-10-17
You can use reshape command:
a= [1 2 3 4;5 6 7 8;9 10 11 12; 13 14 15 16]
b = reshape(a,1,16)
or simply
b = a(:)'
Hope it helps!!!
更多回答(1 个)
manoj saini
2012-10-17
to exact answer >>b=reshape(a',1,16) because matlab always prefer coloum element so pass a'(a transpose) for your exact output
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!