A row vector is a 1-by-n matrix, meaning it has 1 row and multiple columns. For example, [1 2 3] is a row vector with 3 elements.
Click to reveal answer
beginner
What is a column vector in MATLAB?
A column vector is an n-by-1 matrix, meaning it has multiple rows and 1 column. For example, [1; 2; 3] is a column vector with 3 elements.
Click to reveal answer
beginner
How do you create a row vector with elements 4, 5, and 6 in MATLAB?
You write the elements separated by spaces or commas inside square brackets: v = [4 5 6];
Click to reveal answer
beginner
How do you create a column vector with elements 4, 5, and 6 in MATLAB?
You write the elements separated by semicolons inside square brackets: v = [4; 5; 6];
Click to reveal answer
beginner
What is the difference between a row vector and a column vector in MATLAB?
A row vector has one row and many columns, written as [a b c]. A column vector has many rows and one column, written as [a; b; c]. They look different and behave differently in operations.
Click to reveal answer
Which of the following is a row vector in MATLAB?
A[1; 2; 3]
B[1 2 3]
C[1, 2; 3, 4]
D[1; 2, 3]
✗ Incorrect
A row vector has elements in one row separated by spaces or commas: [1 2 3].
How do you separate elements to create a column vector in MATLAB?
AWith spaces
BWith commas
CWith semicolons
DWith periods
✗ Incorrect
Semicolons separate rows, so [1; 2; 3] creates a column vector.
What is the size of a row vector with 5 elements?
A1-by-5
B5-by-1
C5-by-5
D1-by-1
✗ Incorrect
A row vector with 5 elements has 1 row and 5 columns, so size is 1-by-5.
What is the size of a column vector with 4 elements?
A1-by-1
B1-by-4
C4-by-4
D4-by-1
✗ Incorrect
A column vector with 4 elements has 4 rows and 1 column, so size is 4-by-1.
Which MATLAB code creates a column vector?
Av = [7; 8; 9];
Bv = [7 8 9];
Cv = [7, 8, 9];
Dv = [7 8; 9 10];
✗ Incorrect
Using semicolons creates a column vector: [7; 8; 9].
Explain how to create row and column vectors in MATLAB and how they differ.
Think about how elements are separated inside square brackets.
You got /4 concepts.
Describe the size (dimensions) of row and column vectors and why it matters.
Remember rows and columns count.
You got /4 concepts.
Practice
(1/5)
1. Which of the following correctly creates a row vector in MATLAB?
easy
A. v = (1, 2, 3, 4);
B. v = [1 2 3 4];
C. v = [1; 2; 3; 4];
D. v = {1 2 3 4};
Solution
Step 1: Understand row vector syntax
Row vectors use square brackets with spaces or commas between elements.
Step 2: Identify correct option
v = [1 2 3 4]; uses spaces inside square brackets, which is correct for a row vector.
Final Answer:
v = [1 2 3 4]; -> Option B
Quick Check:
Row vector = horizontal elements in [ ] [OK]
Hint: Row vectors use spaces or commas inside [ ] [OK]
Common Mistakes:
Using semicolons creates a column vector, not a row vector
Using parentheses instead of square brackets
Using curly braces creates a cell array, not a vector
2. Which of the following is the correct syntax to create a column vector with elements 5, 6, and 7 in MATLAB?
easy
A. v = [5 6 7];
B. v = (5; 6; 7);
C. v = [5; 6; 7];
D. v = {5; 6; 7};
Solution
Step 1: Recall column vector syntax
Column vectors use square brackets with semicolons separating elements vertically.
Step 2: Find the option matching this syntax
v = [5; 6; 7]; uses semicolons inside square brackets, which is correct for a column vector.
Final Answer:
v = [5; 6; 7]; -> Option C
Quick Check:
Column vector = vertical elements separated by ; [OK]
Hint: Use semicolons inside [ ] for column vectors [OK]
Common Mistakes:
Using spaces instead of semicolons creates a row vector
Using parentheses instead of square brackets
Using curly braces creates a cell array, not a vector
3. What is the output of the following MATLAB code?
v = [10 20 30]; size_v = size(v);
medium
A. [1 1]
B. [3 1]
C. [3 3]
D. [1 3]
Solution
Step 1: Understand the vector shape
v is defined with spaces inside [ ], so it is a row vector with 1 row and 3 columns.
Step 2: Apply size function
size(v) returns the dimensions as [number_of_rows number_of_columns], which is [1 3].
Final Answer:
[1 3] -> Option D
Quick Check:
Row vector size = [1 number_of_elements] [OK]
Hint: Row vector size is 1 row and number of columns [OK]
Common Mistakes:
Confusing row and column vector sizes
Expecting size to return number of elements only
Mixing up output format of size function
4. Identify the error in the following MATLAB code that tries to create a column vector:
v = [1, 2; 3, 4];
medium
A. The vector is actually a 2x2 matrix, not a column vector.
B. The commas should be replaced with semicolons.
C. Square brackets cannot be used for vectors.
D. The semicolon at the end is missing.
Solution
Step 1: Analyze the matrix dimensions
The code uses commas and semicolons inside [ ], which creates a 2x2 matrix, not a column vector.
Step 2: Understand column vector requirements
A column vector must have one column and multiple rows, but this code has 2 rows and 2 columns.
Final Answer:
The vector is actually a 2x2 matrix, not a column vector. -> Option A
Quick Check:
Mixed commas and semicolons create matrices, not vectors [OK]
Hint: Commas separate columns; semicolons separate rows [OK]
Common Mistakes:
Thinking commas separate rows
Assuming semicolons are optional for columns
Confusing matrix with vector shapes
5. You want to create a 1x5 row vector with elements from 1 to 5, then convert it to a 5x1 column vector. Which MATLAB code correctly does this?
hard
A.
rowVec = [1 2 3 4 5];
colVec = rowVec';
B.
rowVec = [1; 2; 3; 4; 5];
colVec = rowVec;
C.
rowVec = [1 2 3 4 5];
colVec = rowVec(:)';
D.
rowVec = [1 2 3 4 5];
colVec = rowVec;
Solution
Step 1: Create a row vector
rowVec = [1 2 3 4 5]; creates a 1x5 row vector using spaces inside square brackets.
Step 2: Convert row vector to column vector
Using the transpose operator (') converts the row vector to a 5x1 column vector.