Bird
0
0

What will be the output of this MATLAB code?

medium📝 Predict Output Q5 of 15
MATLAB - Cell Arrays and Structures
What will be the output of this MATLAB code?
c = {1, 2, 3};
c{4} = 4;
disp(c);
AError: Index exceeds matrix dimensions.
B{1, 2, 3, 4}
C{[1], [2], [3], [4]}
D{[1], [2], [3]}
Step-by-Step Solution
Solution:
  1. Step 1: Understand cell array dynamic expansion

    Assigning to c{4} adds a new cell element at position 4.
  2. Step 2: Check the displayed cell array

    The cell array now has four elements: 1, 2, 3, and 4.
  3. Final Answer:

    {1, 2, 3, 4} -> Option B
  4. Quick Check:

    Cell arrays expand dynamically when indexed beyond size [OK]
Quick Trick: Cell arrays grow automatically when assigning new indices [OK]
Common Mistakes:
  • Expecting an error when adding new cell elements
  • Confusing cell content display with numeric arrays
  • Using parentheses instead of curly braces for assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes