通过在MATLAB App Designer中按下按钮来关闭应用程序?

时间:2018-11-29 15:42:57

标签: matlab button

我使用App设计器来创建滑块和按钮。我希望人们使用滑块指示他们的想法,然后按继续按钮继续进行实验,从而关闭滑块窗口。滑块的值需要存储在变量中,以便以后保存。我似乎无法关闭窗口。你可以帮帮我吗?

classdef AppExampleTrackSlider < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        TrackSliderUIFigure     matlab.ui.Figure
        ContinueButton          matlab.ui.control.Button
        CompletelyOffTaskLabel  matlab.ui.control.Label
        CompletelyOnTaskLabel   matlab.ui.control.Label
        Label                   matlab.ui.control.Label
        Slider_2                matlab.ui.control.Slider
    end

    methods (Access = private)

        % Callback function
        function SliderValueChanging(app, event)
            % Get latest slider value
            changingValue = event.Value;
        end

        % Button pushed function: ContinueButton
        function ContinueButtonPushed(app, event)
            TUT = changingValue;
            disp('Button Pushed')
        end
        % Close request function: TrackSliderUIFigure
            function TrackSliderUIFigureCloseRequest(app, event)
                delete(app)

            end
    end

    % App initialization and construction
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create TrackSliderUIFigure
            app.TrackSliderUIFigure = uifigure;
            app.TrackSliderUIFigure.Position = [100 100 388 280];
            app.TrackSliderUIFigure.Name = 'Track Slider';

            % Create Slider_2
            app.Slider_2 = uislider(app.TrackSliderUIFigure);
            app.Slider_2.Limits = [1 4];
            app.Slider_2.MajorTicks = [1 2 3 4];
            app.Slider_2.Position = [43 132 303 3];
            app.Slider_2.Value = 1;

            % Create ContinueButton
            app.ContinueButton = uibutton(app.TrackSliderUIFigure, 'push');
            app.ContinueButton.ButtonPushedFcn = createCallbackFcn(app, @ContinueButtonPushed, true);
            app.ContinueButton.Position = [150 27 100 22];
            app.ContinueButton.Text = 'Continue';

            % Create CompletelyOffTaskLabel
            app.CompletelyOffTaskLabel = uilabel(app.TrackSliderUIFigure);
            app.CompletelyOffTaskLabel.Position = [1 150 114 22];
            app.CompletelyOffTaskLabel.Text = 'Completely Off Task';

            % Create CompletelyOnTaskLabel
            app.CompletelyOnTaskLabel = uilabel(app.TrackSliderUIFigure);
            app.CompletelyOnTaskLabel.Position = [275 150 114 22];
            app.CompletelyOnTaskLabel.Text = 'Completely On Task';

            % Create Label
            app.Label = uilabel(app.TrackSliderUIFigure);
            app.Label.Position = [12 214 375 67];
            app.Label.Text = {'Please indicate how much your thoughts were focused elsewhere'; 'than the task (Off Task) or focused on the task (On Task). Place the '; 'slider exactly above the integer chosen by you. '};
        end
    end

    methods (Access = public)

        % Construct app
        function app = AppExampleTrackSlider

            % Create and configure components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.TrackSliderUIFigure)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.TrackSliderUIFigure)
        end
    end
end

0 个答案:

没有答案