Recall & Review
beginner
What is a structure array in MATLAB?
A structure array is a data type that groups related data using named fields. Each element in the array can have the same fields but different values.
Click to reveal answer
beginner
How do you create a structure array with fields 'Name' and 'Age' for two people?
Use the syntax: <br> s(1).Name = 'Alice'; s(1).Age = 30;<br> s(2).Name = 'Bob'; s(2).Age = 25;
Click to reveal answer
beginner
How do you access the 'Age' of the second element in a structure array s?
Use s(2).Age to get the age of the second element.
Click to reveal answer
intermediate
Can structure arrays have fields that are themselves arrays or other structures?
Yes, fields in a structure array can hold any data type, including arrays, other structures, or even function handles.
Click to reveal answer
intermediate
How do you add a new field 'Height' to all elements of an existing structure array s?
You can add a new field by assigning it to each element, for example:<br> [s.Height] = deal(170);<br> This sets the 'Height' field to 170 for all elements.
Click to reveal answer
What does s(3).Name represent in a structure array s?
✗ Incorrect
s(3).Name accesses the 'Name' field of the third element in the structure array s.
How do you initialize an empty structure array with fields 'Name' and 'Age'?
✗ Incorrect
Using struct with empty cell arrays for fields creates an empty structure array with specified fields.
Which command adds a field 'City' with value 'NY' to the first element of s?
✗ Incorrect
Assigning s(1).City = 'NY' adds the field 'City' to the first element.
If s is a structure array, what does [s.Age] return?
✗ Incorrect
Using [s.Age] concatenates the 'Age' values from all elements into a numeric array.
Can structure arrays in MATLAB store different data types in different fields?
✗ Incorrect
Structure fields can hold any data type independently.
Explain how to create and access elements in a structure array in MATLAB.
Think about how you store and get data like a contact list.
You got /4 concepts.
Describe how to add a new field to all elements of an existing structure array.
Imagine adding a new column to a table for everyone.
You got /3 concepts.