Bird
0
0

What will be displayed after running this MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - Cell Arrays and Structures
What will be displayed after running this MATLAB code?
fld = 'height';
S.(fld) = 180;
disp(S.height);
AError: Undefined field 'height'
Bfld
C180
D0
Step-by-Step Solution
Solution:
  1. Step 1: Assign value using dynamic field

    The code assigns 180 to field 'height' dynamically.
  2. Step 2: Display field value

    disp(S.height) outputs the value stored in that field, which is 180.
  3. Final Answer:

    180 -> Option C
  4. Quick Check:

    Dynamic assignment sets S.height = 180 [OK]
Quick Trick: Dynamic field assignment sets actual field [OK]
Common Mistakes:
  • Expecting variable name to print instead of value
  • Confusing dynamic field with literal field name
  • Assuming error due to dynamic field usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes