How can I program a listbox/radio button so a selection changes the display of the GUI?
5 次查看(过去 30 天)
显示 更早的评论
In my GUI, I have sliders being used for length, depth, width and radius. I have calculations for properties of a rectangle and circle using the sliders, which then creates a plot for each shape. I want the user to be able to select circle/rectangle from a listbox, and only the calculations and plot for that shape will be displayed on the GUI. How can I do this?
0 个评论
回答(1 个)
Image Analyst
2015-7-29
Put a call into UpdatePlot(handles) in each control that you want to update your plot in:
function UpdatePlot(handles)
% Get the slider values
userLength = get(handles.sldLength, 'Value');
width = get(handles.sldWidth, 'Value');
radius = get(handles.sldRadius, 'Value');
% Get the one listbox item that is selected:
selectedItem = get(handles.listbox1, 'Value');
% Do stuff based on which listbox item they selected.
if selectedItem == 1
% Do circle plot.....
elseif selectedItem == 2
% Do rectangle plot.....
end
% Now here are the callbacks to the listbox and 3 slider controls
% showing how you would call UpdatePlot().
function listbox1_Callback(hObject, eventdata, handles)
UpdatePlot(handles);
function sldLength_Callback(hObject, eventdata, handles)
UpdatePlot(handles);
function sldWidth_Callback(hObject, eventdata, handles)
UpdatePlot(handles);
function sldRadius_Callback(hObject, eventdata, handles)
UpdatePlot(handles);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!