simple way of matrix array resorting

2 views (last 30 days)
Hyun-su Kim on 12 Dec 2019
Commented: Hyun-su Kim on 12 Dec 2019
I have three matrix, A, B, and C.
A = [a1 a2 a3 ...], B = [b1 b2 b3 ...], C = [c1 c2 c3 ...]
I want to create a matrix Q which look like
a1 b1 c1
a2 b2 c2
a3 b3 c3
...
What's simplist code?
Thank you.
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Accepted Answer

Stephen23 on 12 Dec 2019
Robust:
Q = [A(:),B(:),C(:)]
1 CommentShow -1 older commentsHide -1 older comments
Hyun-su Kim on 12 Dec 2019
It works! thanks!

Sign in to comment.

More Answers (2)

Guillaume on 12 Dec 2019
Assuming your 3 vectors are row vectors (i.e. 1xN), then
result = [A; B; C].' %vertically concatenate then transpose
1 CommentShow -1 older commentsHide -1 older comments
Hyun-su Kim on 12 Dec 2019
It gives me 1xn matrix... sorry

Sign in to comment.

Adam on 12 Dec 2019
Q = [A', B', C'];
1 CommentShow -1 older commentsHide -1 older comments
Hyun-su Kim on 12 Dec 2019
I want to have a 3xn matrix.

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!