Challenge - 5 Problems
Structure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Accessing nested structure fields
What is the output of the following MATLAB code?
MATLAB
person.name = 'Alice'; person.age = 30; person.address.city = 'New York'; person.address.zip = 10001; disp(person.address.city);
Attempts:
2 left
💡 Hint
Use dot notation to access nested fields.
✗ Incorrect
The code accesses the nested field 'city' inside 'address' of the 'person' structure, which holds the string 'New York'.
❓ Predict Output
intermediate1:30remaining
Modifying a structure field
What is the value of 'car.color' after running this code?
MATLAB
car.make = 'Toyota'; car.color = 'Red'; car.color = 'Blue';
Attempts:
2 left
💡 Hint
The last assignment changes the field value.
✗ Incorrect
The field 'color' is first set to 'Red' and then changed to 'Blue'. The final value is 'Blue'.
❓ Predict Output
advanced1:30remaining
Accessing a non-existent field
What happens when this MATLAB code runs?
MATLAB
data.temperature = 25;
disp(data.humidity);Attempts:
2 left
💡 Hint
Accessing a field that was never created causes an error.
✗ Incorrect
MATLAB throws an error when trying to access a field that does not exist in the structure.
🧠 Conceptual
advanced2:00remaining
Structure array field access
Given the structure array 'students' below, what is the output of
disp(students(2).name)?MATLAB
students(1).name = 'John'; students(1).grade = 85; students(2).name = 'Emma'; students(2).grade = 92;
Attempts:
2 left
💡 Hint
Use parentheses to access elements in a structure array.
✗ Incorrect
students(2) accesses the second element of the structure array, and '.name' accesses the 'name' field, which is 'Emma'.
❓ Predict Output
expert2:30remaining
Dynamic field names in structures
What is the output of this MATLAB code?
MATLAB
fieldName = 'score'; result.(fieldName) = 100; disp(result.score);
Attempts:
2 left
💡 Hint
You can use parentheses and a variable to access or create fields dynamically.
✗ Incorrect
The code creates a field named 'score' dynamically using the variable 'fieldName' and assigns it 100. Displaying result.score shows 100.