Challenge - 5 Problems
Cell Array Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of cell array indexing with parentheses
What is the output of the following MATLAB code?
MATLAB
C = {10, 20, 30};
result = C(2);
disp(result);Attempts:
2 left
💡 Hint
Parentheses return a cell array subset, not the content inside.
✗ Incorrect
Using parentheses () on a cell array returns a cell array containing the selected cells. So C(2) returns a 1x1 cell array with the second element inside, not the element itself.
❓ Predict Output
intermediate2:00remaining
Output of cell array indexing with curly braces
What is the output of this MATLAB code?
MATLAB
C = {10, 20, 30};
result = C{2};
disp(result);Attempts:
2 left
💡 Hint
Curly braces extract the content inside the cell.
✗ Incorrect
Using curly braces {} extracts the content inside the cell. So C{2} returns the numeric value 20 directly.
❓ Predict Output
advanced2:00remaining
Result of combining parentheses and curly braces
What is the output of this MATLAB code snippet?
MATLAB
C = {1, {2, 3}, 4};
result = C{2}(1);
disp(result);Attempts:
2 left
💡 Hint
C{2} extracts the second cell content, which is itself a cell array.
✗ Incorrect
C{2} extracts {2,3}, a cell array. Then (1) indexes the first element of that cell array with parentheses, returning a 1x1 cell array containing 2.
❓ Predict Output
advanced2:00remaining
Output when mixing parentheses and curly braces incorrectly
What error or output does this MATLAB code produce?
MATLAB
C = {1, 2, 3};
result = C{1}(2);
disp(result);Attempts:
2 left
💡 Hint
C{1} extracts the numeric 1, which is scalar and cannot be indexed at (2).
✗ Incorrect
C{1} is the numeric value 1. Trying to index (2) on a scalar number causes an 'Index exceeds matrix dimensions' error.
🧠 Conceptual
expert2:00remaining
Difference between parentheses and curly braces in cell arrays
Which statement correctly describes the difference between using parentheses () and curly braces {} when indexing cell arrays in MATLAB?
Attempts:
2 left
💡 Hint
Think about what type of output you get from each indexing style.
✗ Incorrect
Parentheses () return a subset of the cell array as a cell array. Curly braces {} extract the actual content inside the cell.