Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
MATLAB - Cell Arrays and Structures
Identify the error in this code:
person = struct('name', 'Anna');
disp(person['name']);
AMissing semicolon after struct
BUsing square brackets for field access
CIncorrect field name 'name'
Dstruct function syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check field access syntax

    MATLAB uses dot notation, not square brackets, to access structure fields.
  2. Step 2: Identify the error

    person['name'] is invalid syntax and causes an error.
  3. Final Answer:

    Using square brackets for field access -> Option B
  4. Quick Check:

    Field access must use dot, not brackets = B [OK]
Quick Trick: Use dot, not brackets, to access structure fields [OK]
Common Mistakes:
  • Using brackets like arrays
  • Confusing with other languages syntax
  • Ignoring MATLAB error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes