I am creating a program in AppDesigner, and I want to initialize some variables and hide buttons and textboxes, for that I understand that StartupFcn exists but I am not getting that option, I cannot use that callback, only CloseRequestFcn and ButtonDownFcn appear.
MATLAB: Problems with the Startupfcn URG!!!!!!!
MATLABurg!!!
Related Solutions
Hi,
I suggest using 'SelectionChangedFcn' callback. This is notified whenever a state button(zoom/pan) is clicked, and you can know which button is clicked. You can also write your custom MATLAB code in the callback associated.
Refer the documentation link for more details:
You can do this by using a callback on changinge the value in your first drop down. All the magic is done in
function DropDown1ValueChanged(app, event)
Here you go:
classdef app1 < matlab.apps.AppBase % Properties that correspond to app components
properties (Access = public) UIFigure matlab.ui.Figure DropDown2_2Label matlab.ui.control.Label DropDown2_2 matlab.ui.control.DropDown DropDown1Label matlab.ui.control.Label DropDown1 matlab.ui.control.DropDown end methods (Access = private) % Value changed function: DropDown1
function DropDown1ValueChanged(app, event) value = app.DropDown1.Value; switch value case "California" app.DropDown2_2.Items = {'San Diego', 'Sacaramento', 'Irvine'}; case "Texas" app.DropDown2_2.Items = {'Austin', 'Dallas', 'Houston'}; end end end % App initialization and construction
methods (Access = private) % Create UIFigure and components
function createComponents(app) % Create UIFigure
app.UIFigure = uifigure; app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'UI Figure'; % Create DropDown2_2Label
app.DropDown2_2Label = uilabel(app.UIFigure); app.DropDown2_2Label.HorizontalAlignment = 'right'; app.DropDown2_2Label.Position = [370 287 69 22]; app.DropDown2_2Label.Text = 'DropDown2'; % Create DropDown2_2
app.DropDown2_2 = uidropdown(app.UIFigure); app.DropDown2_2.Items = {'San Diego', 'Sacaramento', 'Irvine'}; app.DropDown2_2.Position = [454 287 100 22]; app.DropDown2_2.Value = 'San Diego'; % Create DropDown1Label
app.DropDown1Label = uilabel(app.UIFigure); app.DropDown1Label.HorizontalAlignment = 'right'; app.DropDown1Label.Position = [97 287 69 22]; app.DropDown1Label.Text = 'DropDown1'; % Create DropDown1
app.DropDown1 = uidropdown(app.UIFigure); app.DropDown1.Items = {'California', 'Texas'}; app.DropDown1.ValueChangedFcn = createCallbackFcn(app, @DropDown1ValueChanged, true); app.DropDown1.Position = [181 287 100 22]; app.DropDown1.Value = 'California'; end end methods (Access = public) % Construct app
function app = app1 % Create and configure 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 endend
Greetins Stefan
Best Answer