MATLAB Interface 5 — Questions and Answers
Question 1: Which MATLAB function creates a toolbar button on a figure's toolbar?
- uipushtool (Correct answer)
- addtoolbar
- toolbutton
- uitoolbutton
Correct answer: uipushtool
uipushtool adds a push button to a uitoolbar object, which itself is attached to a figure.
Question 2: What is the purpose of the 'UserData' property available on all MATLAB graphics objects?
- Store arbitrary user-defined data attached to the object (Correct answer)
- Display user information in the figure
- Set access permissions
- Log user interactions
Correct answer: Store arbitrary user-defined data attached to the object
UserData can hold any MATLAB variable, providing a convenient way to attach custom data to any graphics handle.
Question 3: In MATLAB, which function allows you to programmatically simulate a button click on a uicontrol?
- uicontrol callbacks must be called directly (Correct answer)
- clickbutton
- pressbutton
- simulate
Correct answer: uicontrol callbacks must be called directly
There is no built-in clickbutton function; to trigger behavior you invoke the callback function directly with the required arguments.
Question 4: Which property of a MATLAB edit box (uicontrol Style='edit') allows multiline text input?
- Max set to a value greater than 1 (Correct answer)
- Multiline set to true
- Lines set to 'multi'
- Style set to 'textarea'
Correct answer: Max set to a value greater than 1
Setting Max > 1 (typically Max=2) on an edit uicontrol enables multiline input with scrolling.
Question 5: In App Designer, what does the startup function (startupFcn) allow you to do?
- Initialize component values and app state before the UI is shown (Correct answer)
- Define keyboard shortcuts
- Set the window icon
- Register external callbacks
Correct answer: Initialize component values and app state before the UI is shown
startupFcn runs automatically after the app is created, making it the correct place to initialize data and set default component values.
Question 6: Which MATLAB function returns the handle of the currently active figure?
- gcf (Correct answer)
- gca
- gco
- gcobj
Correct answer: gcf
gcf (get current figure) returns the handle of the figure that most recently had focus or was interacted with.
Question 7: What does the 'Position' property of a MATLAB figure specify?
- [left, bottom, width, height] in units relative to the screen (Correct answer)
- [x, y, width, height] from top-left corner
- [row, col, width, height] in pixels
- [left, top, right, bottom] margins
Correct answer: [left, bottom, width, height] in units relative to the screen
Position is a four-element vector [left, bottom, width, height] measured from the bottom-left of the primary display in the current Units.
Which MATLAB function creates a toolbar button on a figure's toolbar?