Consider the following MATLAB code that creates a simple UI figure with a button. What will be displayed when the button is clicked?
fig = uifigure('Name','Test UI'); btn = uibutton(fig,'push','Text','Click me'); btn.ButtonPushedFcn = @(btn,event) disp('Button clicked!');
Think about where disp outputs text in MATLAB.
The disp function prints text to the MATLAB command window, so clicking the button will print 'Button clicked!' there.
In MATLAB UI design, which component allows the user to select exactly one option from a list?
Think about grouping radio buttons to allow only one selection.
A uiradiobuttongroup contains multiple radio buttons and ensures only one can be selected at a time.
Examine the code below. Why does it cause an error when run?
fig = uifigure; btn = uibutton(fig,'Text','Press'); btn.ButtonPushedFcn = @buttonCallback; function buttonCallback(src,event) disp('Pressed'); end
Consider MATLAB's rules about local functions in scripts.
In MATLAB scripts, local functions must be at the end of the file or saved separately. Here, the callback is defined after the script code, causing an error.
Choose the correct syntax to create a dropdown menu with options 'Red', 'Green', 'Blue' in a MATLAB UI figure.
Check the order and names of input arguments for uidropdown.
The correct syntax uses name-value pairs with 'Parent' first, then 'Items', then 'Value'. Passing the figure as first argument without name is invalid.
Given the code below, how many items will the dropdown contain?
fig = uifigure; dd = uidropdown(fig,'Items',{'One','Two','Three'}); items = dd.Items; items{end+1} = 'Four'; dd.Items = items;
Think about how the Items property is updated.
The code gets the current items, adds 'Four' to the list, then assigns it back. So the dropdown has 4 items after running.
