Bird
0
0

How do you access the field 'age' of the first element in a structure array named 'person'?

easy📝 Conceptual Q2 of 15
MATLAB - Cell Arrays and Structures
How do you access the field 'age' of the first element in a structure array named 'person'?
Aperson.age(1)
Bperson.age{1}
Cperson(1).age
Dperson{1}.age
Step-by-Step Solution
Solution:
  1. Step 1: Recall syntax for accessing fields in structure arrays

    Use parentheses for indexing elements and dot for fields: person(1).age.
  2. Step 2: Evaluate each option

    person(1).age uses correct syntax. The other options misuse indexing or braces.
  3. Final Answer:

    person(1).age -> Option C
  4. Quick Check:

    Access field with (index).field = person(1).age [OK]
Quick Trick: Use parentheses for element, dot for field: structArray(index).field [OK]
Common Mistakes:
  • Using curly braces {} instead of parentheses ().
  • Trying to index the field directly without element index.
  • Mixing up field and element indexing.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes