Bird
0
0

Which of the following is the correct syntax to assign a value to a dynamic field name fname in a structure S?

easy📝 Syntax Q12 of 15
MATLAB - Cell Arrays and Structures
Which of the following is the correct syntax to assign a value to a dynamic field name fname in a structure S?
AS.(fname) = 10;
BS.fname = 10;
CS{fname} = 10;
DS[fname] = 10;
Step-by-Step Solution
Solution:
  1. Step 1: Recall MATLAB syntax for dynamic fields

    Dynamic field names use parentheses and dot notation: structure.(variableName).
  2. Step 2: Check each option

    S.(fname) = 10; uses S.(fname) which is correct syntax. Options A, C, and D are invalid for dynamic field names.
  3. Final Answer:

    S.(fname) = 10; -> Option A
  4. Quick Check:

    Use dot and parentheses for dynamic fields [OK]
Quick Trick: Use S.(variable) to access dynamic fields [OK]
Common Mistakes:
  • Using dot without parentheses for variable field
  • Using curly braces or square brackets instead of dot
  • Confusing cell or array indexing with struct fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes