Selecting a dropdown value and getting an answer AFTER pressing button (in App Designer)
Afficher commentaires plus anciens
Hi there,
I've been trying to build a GUI in App Designer where:
- you select a certain drop down value;
- You press a button;
- You get a message or the answer displayed in a text box, depending on the selected drop down value.
I can't seem to get this done though. I don't really know how to connect the selected drop down value to a certain outcome in the textbox, AFTER the button is pressed. In fact, I'm generally struggling with these callback functions.
Can anyone help me?
My current code is as follows:
methods (Access = private)
% Callback function
function ScenarioDropDownValueChanged(app, event)
value = app.ScenarioDropDown.Value;
end
% Button pushed function: BerekenenButton
function BerekenenButtonPushed(app, event)
if ScenarioDropDownValueChanged(value,'-kies-')
app.BestesystemenTextArea.Value='error, select scenario'
elseif ScenarioDropDownValueChanged(value,'Selection1')
app.BestesystemenTextArea.Value='Systeem 1'
else app.BestesystemenTextArea.Value='Systeem 2'
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create BerekenenButton
app.BerekenenButton = uibutton(app.UIFigure, 'push');
app.BerekenenButton.ButtonPushedFcn = createCallbackFcn(app, @BerekenenButtonPushed, true);
app.BerekenenButton.FontWeight = 'bold';
app.BerekenenButton.Position = [266 219 100 22];
app.BerekenenButton.Text = 'Berekenen';
% Create BestesystemenTextArea
app.BestesystemenTextArea = uitextarea(app.UIFigure);
app.BestesystemenTextArea.Position = [272 97 150 60];
% Create ScenarioDropDown
app.ScenarioDropDown = uidropdown(app.UIFigure);
app.ScenarioDropDown.Items = {'-kies-', 'Selection1', 'Selection2', 'Selection3'};
app.ScenarioDropDown.ValueChangedFcn = createCallbackFcn(app, @ScenarioDropDownValueChanged, true);
app.ScenarioDropDown.Position = [281 368 145 22];
app.ScenarioDropDown.Value = '-kies-';
end
Thank you,
Jo
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!