Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Bus object named 'myBus' with elements 'speed' and 'acceleration'.
Simulink
myBus = Simulink.Bus.createObject('myBus'); myBusObj = [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name 'Simulink.Bus' instead of the variable holding the Bus object.
Using undefined names like 'BusObject' or 'Bus'.
✗ Incorrect
The variable 'myBus' holds the Bus object created by Simulink.Bus.createObject, so assigning it to 'myBusObj' requires using 'myBus'.
2fill in blank
mediumComplete the code to add a new element 'temperature' of type 'single' to an existing Bus object 'myBusObj'.
Simulink
newElement = Simulink.BusElement; newElement.Name = 'temperature'; newElement.DataType = [1]; myBusObj.Elements(end+1) = newElement;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'double' or other types instead of 'single'.
Not using quotes around the data type string.
✗ Incorrect
The new element 'temperature' should be of type 'single', so the DataType property must be set to 'single'.
3fill in blank
hardFix the error in the code to correctly create a Bus object with two elements 'voltage' and 'current'.
Simulink
elems(1) = Simulink.BusElement; elems(1).Name = 'voltage'; elems(1).DataType = 'double'; elems(2) = Simulink.BusElement; elems(2).Name = 'current'; elems(2).DataType = [1]; busObj = Simulink.Bus; busObj.Elements = elems;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'boolean' which are invalid for numeric signals.
Using different numeric types causing incompatibility.
✗ Incorrect
Both elements should have compatible numeric types; 'current' should be 'double' like 'voltage' to avoid errors.
4fill in blank
hardFill both blanks to create a Bus object with elements 'pressure' and 'flowRate' of type 'single'.
Simulink
elems(1) = Simulink.BusElement; elems(1).Name = [1]; elems(1).DataType = 'single'; elems(2) = Simulink.BusElement; elems(2).Name = [2]; elems(2).DataType = 'single'; busObj = Simulink.Bus; busObj.Elements = elems;
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong names like 'temperature' or 'speed'.
Missing quotes around the names.
✗ Incorrect
The Bus elements must be named 'pressure' and 'flowRate' as specified.
5fill in blank
hardFill all three blanks to create a Bus object with elements named in uppercase and data types 'double' and 'single'.
Simulink
elems(1) = Simulink.BusElement; elems(1).Name = [1]; elems(1).DataType = 'double'; elems(2) = Simulink.BusElement; elems(2).Name = [2]; elems(2).DataType = [3]; busObj = Simulink.Bus; busObj.Elements = elems;
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names instead of uppercase.
Mixing up data types for elements.
✗ Incorrect
The first element is named 'VOLTAGE' with type 'double', the second 'SPEED' with type 'single'.
