Migrating popupmenu from guide to app designer
    15 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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 件のコメント
  Tommy
      
 2020 年 4 月 20 日
				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
採用された回答
  Ajay Pattassery
    
 2020 年 5 月 28 日
        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 件のコメント
その他の回答 (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!


