Matlab Arrays vs. Matrices Quiz
35 questions exploring the core data structures in MATLAB, focusing on dimensionality, indexing, and manipulation techniques.
Question 1
In MATLAB, what is the technical definition of a single scalar number like `5`?
Question 2
You have a matrix `M` of size 3x3. You wish to access the element located in the second row and third column. Which command achieves this?
Question 3
Consider the code above. `A` is a 2x3 matrix. After reshaping it into a 3x2 matrix `B`, what value will be at `B(2, 1)`?
A = [1 2 3; 4 5 6];
B = reshape(A, 3, 2);Question 4
What is the primary difference between a row vector and a column vector?
Question 5
You initialize a vector `v` with three elements. You then assign a value to the 5th index. What happens to the 4th element?
v = [10, 20, 30];
v(5) = 50;Question 6
Which syntax correctly concatenates two row vectors `A` and `B` horizontally (end-to-end)?
Question 7
You are using linear indexing on a 2x2 matrix `M`. Which element does `M(3)` retrieve?
M = [1 2; 3 4];
val = M(3);Question 8
When reshaping a matrix, what constraint must be satisfied regarding the number of elements?
Question 9
Given two row vectors `A` and `B`, you execute the code above. What are the dimensions of the resulting matrix `C`?
A = [1 2 3];
B = [4 5 6];
C = [A; B];Question 10
What does the keyword `end` represent when used inside an indexing expression like `v(end)`?
Question 11
You create a matrix using the command `zeros(2, 4)`. How many total elements does this matrix contain?
M = zeros(2, 4);Question 12
Which command would you use to find the dimensions (rows and columns) of a matrix `A`?
Question 13
What is the effect of assigning an empty matrix `[]` to the second column of `A`?
A = [10 20; 30 40];
A(:, 2) = [];Question 14
If you try to vertically concatenate matrices `A` and `B` using `[A; B]`, what condition must be met?
Question 15
You extract a sub-matrix `sub` from `M` using the indices `1:2` for rows and `2:3` for columns. What does `sub` look like?
M = [1 2 3; 4 5 6; 7 8 9];
sub = M(1:2, 2:3);Question 16
What is the result of `length(M)` if `M` is a 4x10 matrix?
Question 17
This question tests matrix multiplication rules, which depend on dimensions. `A` is 1x2. `B` is 2x1. What is the size of the result `C`?
A = [1 2];
B = [3; 4];
C = A * B;Question 18
How does MATLAB store a 2D matrix in memory?
Question 19
You use the index vector `[1 1 1]` to access elements of `v`. What does `res` contain?
v = 1:5;
idx = [1 1 1];
res = v(idx);Question 20
Which function creates an identity matrix (ones on diagonal, zeros elsewhere)?
Question 21
You have a vector `A = [1 2 3]`. You delete the second element. What is the new value of `A`?
A = [1 2 3];
A(2) = [];Question 22
What is a 'scalar' in the context of MATLAB array operations?
Question 23
The `magic(3)` function creates a 3x3 matrix. You use `M(:, end)` to create `last_col`. What does the colon `:` signify here?
M = magic(3);
last_col = M(:, end);Question 24
If you assign `A(5,5) = 1` to a variable `A` that doesn't exist yet, what does MATLAB do?
Question 25
You use `cat(3, A, B)` to concatenate two 1x2 vectors along the 3rd dimension. What is the size of `C`?
A = [1 2];
B = [3 4];
C = cat(3, A, B);Question 26
Which operator is used to transpose a real matrix (swap rows and columns)?
Question 27
`A` is a column vector. You apply the transpose operator `.'`. What is `B`?
A = [10; 20; 30];
B = A.';Question 28
What is the result of `numel(zeros(3, 4))`?
Question 29
You use `reshape(A, [], 2)`. What does the empty bracket `[]` tell MATLAB to do?
A = [1 2 3 4];
B = reshape(A, [], 2);Question 30
Can a matrix contain different data types (e.g., numbers and strings mixed)?
Question 31
The `sub2ind` function converts row/col subscripts to a linear index. For a 2x2 matrix, what is the linear index of row 2, column 1?
A = [1 2; 3 4];
idx = sub2ind(size(A), 2, 1);Question 32
What happens if you index with a logical mask that is the same size as the matrix?
Question 33
This is an advanced broadcasting question. `A` is 1x3. `B` is 3x1. What is the size of `A + B` in modern MATLAB?
A = [1 2 3];
B = [1; 2; 3];
C = A + B;Question 34
Which function flips a matrix upside down (reverses the order of rows)?
Question 35
You assign 10 to `A(:)`. What is the result?
A = [1 2; 3 4];
A(:) = 10;