0
0
MATLABdata~20 mins

Structures and field access in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Structure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
AError: Field 'city' does not exist
Bperson.address.city
C10001
DNew York
Attempts:
2 left
💡 Hint
Use dot notation to access nested fields.
Predict Output
intermediate
1: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';
AError: Cannot modify field
B'Red'
C'Blue'
D'' (empty string)
Attempts:
2 left
💡 Hint
The last assignment changes the field value.
Predict Output
advanced
1:30remaining
Accessing a non-existent field
What happens when this MATLAB code runs?
MATLAB
data.temperature = 25;
disp(data.humidity);
AError: Reference to non-existent field 'humidity'.
BDisplays 0
CDisplays empty array []
DDisplays NaN
Attempts:
2 left
💡 Hint
Accessing a field that was never created causes an error.
🧠 Conceptual
advanced
2: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;
AJohn
BEmma
C85
DError: Index exceeds array bounds
Attempts:
2 left
💡 Hint
Use parentheses to access elements in a structure array.
Predict Output
expert
2:30remaining
Dynamic field names in structures
What is the output of this MATLAB code?
MATLAB
fieldName = 'score';
result.(fieldName) = 100;
disp(result.score);
A100
BfieldName
CError: Invalid field name
D[]
Attempts:
2 left
💡 Hint
You can use parentheses and a variable to access or create fields dynamically.