开发者

convert into a single row matrix [duplicate]

This question already has answers here: 开发者_如何学Python How do you concatenate the rows of a matrix into a vector? (2 answers) Closed 5 years ago.

I have a matrix say a = [1 5 9;7 8 5; 7 1 4];

I want to make a linear matrix of a i.e., a1 = [1 5 9 7 8 5 7 1 4];


a'(:)' %# Octave
b= a'; b(:)' %# Matlab

For more information on column-major order and on colon.

Added, more verbose variations may be occasionally practical as well:

a'(ind2sub([3 3], 1: 9))
permute(a, [2 1])(ind2sub([3 3], 1: 9))

Here permute(a, [2 1]) is now equivalent to a.'.


One more variant

a = reshape( a.', 1, numel(a) )

Note use of .' to get the non-conjugated TRANSPOSE - ' corresponds to CTRANSPOSE


This is how you do it in Matlab

a1 = a(:);

Or if you need to go by rows, transpose it before and after:

b = a';
b1 = b(:);
a1 = b1';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜