Bird
0
0

Which of the following is the correct way to create a structure array with fields 'Name' and 'Age' in MATLAB?

easy📝 Syntax Q12 of 15
MATLAB - Cell Arrays and Structures
Which of the following is the correct way to create a structure array with fields 'Name' and 'Age' in MATLAB?
Aperson = struct('Name', 'Alice', 'Age', 30);
Bperson = struct(Name = 'Alice', Age = 30);
Cperson = struct['Name', 'Alice', 'Age', 30];
Dperson = struct{'Name', 'Alice', 'Age', 30};
Step-by-Step Solution
Solution:
  1. Step 1: Recall MATLAB struct syntax

    MATLAB uses struct('field1', value1, 'field2', value2) to create structures.
  2. Step 2: Check each option's syntax

    person = struct('Name', 'Alice', 'Age', 30); uses correct parentheses and quotes. Options B, C, D use invalid syntax.
  3. Final Answer:

    person = struct('Name', 'Alice', 'Age', 30); -> Option A
  4. Quick Check:

    struct uses parentheses and quotes [OK]
Quick Trick: Use parentheses and quotes with struct() [OK]
Common Mistakes:
  • Using square or curly brackets instead of parentheses
  • Omitting quotes around field names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes