Migrating popupmenu from guide to app designer
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dick Curran
am 20 Apr. 2020
Beantwortet: Ajay Pattassery
am 28 Mai 2020
I have an application based on guide that uses the popupmenu control. The dropdown control available in app designer does not have the same capabilities, such as changing the items at run time.
2 Kommentare
Tommy
am 20 Apr. 2020
This was a simple app I wrote a few days ago which updates the items in a drop down based on the value of a slider. Other properties of the drop down, such as 'ItemsData' and 'ValueChangedFcn', can be updated in a similar manner. Are you looking for something like this?
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
DropDownLabel matlab.ui.control.Label
DropDown matlab.ui.control.DropDown
SliderLabel matlab.ui.control.Label
Slider matlab.ui.control.Slider
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: Slider
function SliderValueChanged(app, event)
value = app.Slider.Value;
app.DropDown.Items = compose('Option %d', 1:(floor(value/20)+1));
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create DropDownLabel
app.DropDownLabel = uilabel(app.UIFigure);
app.DropDownLabel.HorizontalAlignment = 'right';
app.DropDownLabel.Position = [68 319 66 22];
app.DropDownLabel.Text = 'Drop Down';
% Create DropDown
app.DropDown = uidropdown(app.UIFigure);
app.DropDown.Items = {'Option 1'};
app.DropDown.Position = [149 319 100 22];
% Create SliderLabel
app.SliderLabel = uilabel(app.UIFigure);
app.SliderLabel.HorizontalAlignment = 'right';
app.SliderLabel.Position = [322 330 36 22];
app.SliderLabel.Text = 'Slider';
% Create Slider
app.Slider = uislider(app.UIFigure);
app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
app.Slider.Position = [379 339 150 3];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
Akzeptierte Antwort
Ajay Pattassery
am 28 Mai 2020
If you want to control the drop-down menu during runtime, create the drop-down menu programmatically.
The property 'Items' can be used to control what all to be listed in the drop-down menu.
Also, the 'Parent' property can be used to control where the drop-down menu needs to be placed. The position can be further finetuned by adjusting the 'Position' property.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!