0
0
MATLABdata~20 mins

Matrix concatenation in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Concatenation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of horizontal concatenation?
Consider the following MATLAB code:
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [A B];
disp(C);

What will be displayed?
MATLAB
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [A B];
disp(C);
A[1 2 5 6; 3 4 7 8]
B[1 2 3 4; 5 6 7 8]
C[6 8; 10 12]
D[1 2; 3 4; 5 6; 7 8]
Attempts:
2 left
💡 Hint
Horizontal concatenation joins matrices side by side, so columns add up.
Predict Output
intermediate
2:00remaining
What is the output of vertical concatenation?
Given the MATLAB code:
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [A; B];
disp(C);

What will be displayed?
MATLAB
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [A; B];
disp(C);
A[1 2 5 6; 3 4 7 8]
B[1 2; 3 4; 5 6; 7 8]
C[6 8; 10 12]
D[1 2; 3 4; 1 2; 3 4]
Attempts:
2 left
💡 Hint
Vertical concatenation stacks matrices on top of each other, so rows add up.
Predict Output
advanced
2:00remaining
What error occurs with mismatched dimensions in horizontal concatenation?
What happens when you run this MATLAB code?
A = [1 2; 3 4];
B = [5 6 7];
C = [A B];
MATLAB
A = [1 2; 3 4];
B = [5 6 7];
C = [A B];
AC = [1 2 5 6 7; 3 4 5 6 7]
BC = [6 8 7; 10 12 7]
CError: Dimensions of matrices being concatenated are not consistent.
DC = [1 2; 3 4; 5 6; 7]
Attempts:
2 left
💡 Hint
Horizontal concatenation requires the same number of rows.
Predict Output
advanced
2:00remaining
What is the output of nested concatenation?
What does this MATLAB code output?
A = [1 2];
B = [3 4];
C = [5 6];
D = [A; B C];
disp(D);
MATLAB
A = [1 2];
B = [3 4];
C = [5 6];
D = [A; B C];
disp(D);
AError: Dimensions of matrices being concatenated are not consistent.
B[1 2; 3 4; 5 6]
C[1 2; 3 4 5 6]
D[1 2 3 4 5 6]
Attempts:
2 left
💡 Hint
Check the sizes of B and C before concatenation.
🧠 Conceptual
expert
2:00remaining
How many elements are in the resulting matrix after concatenation?
Given these matrices:
A = ones(3,4);
B = zeros(3,2);
C = [A B];

How many elements does matrix C contain?
MATLAB
A = ones(3,4);
B = zeros(3,2);
C = [A B];
A24
B20
C12
D18
Attempts:
2 left
💡 Hint
Count rows and columns after concatenation, then multiply.