Put 3 columns of two matrix in 1 row matrix

3 ビュー (過去 30 日間)
Phong Pham
Phong Pham 2013 年 11 月 15 日
回答済み: Andrei Bobrov 2013 年 11 月 15 日
I have matrix X and Y with dimension of 100 x 3
X= [ x1 x2 x3; x4 x5 x6; etc];
Y=[ y1 y2 y3; y4 y5 y6; etc];
Now I want a matrix that combines X and Y with the format as following
XY= [ x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6, etc]
I have tried XY=reshape([ X, Y].',1,[]); but it gave me XY=[ x1 x2 x3 y1 y2 y3 ]
Please helps

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 15 日
編集済み: Azzi Abdelmalek 2013 年 11 月 15 日
X=[1 2 3;4 5 6];
Y=[11 22 33;44 55 66]
X=X';
Y=Y';
a=[X(:) Y(:)]'
out=a(:)'

その他の回答 (3 件)

Walter Roberson
Walter Roberson 2013 年 11 月 15 日
reshape([X;Y])
  1 件のコメント
Phong Pham
Phong Pham 2013 年 11 月 15 日
Gave me an error " Not enough input arguments"

サインインしてコメントする。


Image Analyst
Image Analyst 2013 年 11 月 15 日
Try this way:
% Create sample data.
numberOfRows = 5;
x = randi(9, numberOfRows, 3)
y = randi(9, numberOfRows, 3)
% Create the desired output array.
XY = zeros(1, numel(x)+numel(y)); % Initialize
% Stuff in the x
XY(1:2:end) = x';
% Stuff in the y
XY(2:2:end) = y'

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 15 日
reshape(permute(cat(3,X,Y),[3, 2, 1]),1,[])

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by