0
0
MATLABdata~20 mins

Cell array creation in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cell Array 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 this cell array creation code?
Consider the following MATLAB code that creates a cell array. What will be the content of C after running it?
MATLAB
C = {1, 'text', [2 3 4]; true, {5,6}, pi};
disp(C);
AA 2x3 cell array where C{1,1} is the string '1' and C{2,2} is the number 6
BA 3x2 cell array with numbers and strings mixed incorrectly causing an error
CA numeric matrix with elements 1, 'text', [2 3 4], true, {5,6}, pi
DA 2x3 cell array where C{1,2} is the string 'text' and C{2,3} is the number pi
Attempts:
2 left
💡 Hint
Remember that curly braces {} create cell arrays and each element can hold different types.
Predict Output
intermediate
1:00remaining
What is the size of the cell array created here?
What is the size of the cell array C after executing this code?
C = cell(3,2);
MATLAB
C = cell(3,2);
sizeC = size(C);
A[3 2]
B[2 3]
C[1 6]
D[6 1]
Attempts:
2 left
💡 Hint
The cell function creates a cell array with the given number of rows and columns.
🔧 Debug
advanced
1:30remaining
Identify the error in this cell array creation
This code is intended to create a 1x3 cell array with different types of elements. What error will MATLAB show when running it?
C = {1, 2, 3; 4, 5};
MATLAB
C = {1, 2, 3; 4, 5};
AError: Dimensions of arrays being concatenated are not consistent.
BNo error, creates a 2x3 cell array with missing elements filled with empty cells.
CError: Cell arrays cannot contain numeric values.
DError: Missing semicolon at the end of the line.
Attempts:
2 left
💡 Hint
Check the number of elements in each row when creating a cell array with multiple rows.
🧠 Conceptual
advanced
1:30remaining
Which option correctly creates a nested cell array?
You want to create a cell array C where the second element is itself a cell array containing numbers 10 and 20. Which code does this correctly?
AC = {5; {10, 20}; 'hello'};
BC = {5, [10, 20], 'hello'};
CC = {5, {10, 20}, 'hello'};
DC = {5, {10; 20}, 'hello'};
Attempts:
2 left
💡 Hint
Use curly braces inside the cell array to create nested cells.
Predict Output
expert
2:00remaining
What is the output of this complex cell array indexing?
Given the cell array C = {1, {2, 3}, 4};, what is the output of disp(C{2}{1})?
MATLAB
C = {1, {2, 3}, 4};
disp(C{2}{1});
A3
B2
C{2, 3}
DError: Cell contents reference from a non-cell array object.
Attempts:
2 left
💡 Hint
Remember that C{2} accesses the second cell content, which is itself a cell array, then {1} accesses its first element.