Clear Filters
Clear Filters

Can you use the concatenation ability of MATLAB to combine a 3x4 and a 3x5 matrix?

1 view (last 30 days)
If yes, how we can do this?
  1 Comment
Stephen23
Stephen23 on 31 Aug 2017
Edited: Stephen23 on 31 Aug 2017
[A,B]
horzcat(A,B)
cat(2,A,B)
Did you try searching for this before asking? MATLAB has documentation which is very easy to search.

Sign in to comment.

Accepted Answer

OCDER
OCDER on 31 Aug 2017
Yes you can, as long as the row or column dimensions matches.
A = zeros(3, 4) % A 3x4 matrix
B = ones(3, 5) % a 3x5 matrix
AB = cat(2, A, B) %Concatenate along column dimension (dim = 2), resulting in a 3x9 matrix
AB = [A B] %Same thing as cat(2, A, B)

More Answers (1)

Omur Bas
Omur Bas on 31 Aug 2017
Simply use square brackets, as you would use for combining scalars into a vector:
A = ones(3,4);
B = zeros(3,5);
AB= [A B];

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!