my question is if a=[1 2;3 4],b=[5 6;7 8],c=[9 10;11 12] the resultant matrix should be d=[1 5 9;2 6 10;3 7 11;4 8 12] this should be done using for loop?

4 views (last 30 days)
my question is if a=[1 2;3 4],b=[5 6;7 8],c=[9 10;11 12]
the resultant matrix should be d=[1 5 9;2 6 10;3 7 11;4 8 12] this should be done using for loop?
  2 Comments
DGM
DGM on 13 Jan 2025
Nobody suggested that the goal was to take the sum. The given result for d is clearly done by reshaping the contents of a, b, and c as is shown in the other comments.
a = [1 2;3 4];
b = [5 6;7 8];
c = [9 10;11 12];
d = reshape([a; b; c].',[],3)
d = 4×3
1 5 9 2 6 10 3 7 11 4 8 12
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Sign in to comment.

Accepted Answer

Torsten
Torsten on 11 Aug 2017
Maybe
d = [a(:) b(:) c(:)]
?
Best wishes
Torsten.
  6 Comments
Torsten
Torsten on 11 Aug 2017
Edited: Torsten on 11 Aug 2017
Writing the transposed matrix as column vector does not work this way ?
Any recommendation ?
Best wishes
Torsten.
Torsten
Torsten on 11 Aug 2017
Don't know "Julia", but a combination of both features (.' and (:)) in one command line is quite intuitive.
Less cumbersome than
a=a.';
b=b.';
c=c.';
d=[a(:) b(:) c(:)];
Best wishes
Torsten.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!