classdef app1 < matlab.apps.AppBase
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)
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
methods (Access = private)
function createComponents(app)
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
app.DropDown2_2Label = uilabel(app.UIFigure);
app.DropDown2_2Label.HorizontalAlignment = 'right';
app.DropDown2_2Label.Position = [370 287 69 22];
app.DropDown2_2Label.Text = 'DropDown2';
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';
app.DropDown1Label = uilabel(app.UIFigure);
app.DropDown1Label.HorizontalAlignment = 'right';
app.DropDown1Label.Position = [97 287 69 22];
app.DropDown1Label.Text = '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)
function app = app1
createComponents(app)
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end
Best Answer