2021-04-03 MatlabGUI

image.png

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure      matlab.ui.Figure
        LoadButton    matlab.ui.control.Button
        UIAxes        matlab.ui.control.UIAxes
        SliderLabel   matlab.ui.control.Label
        Slider        matlab.ui.control.Slider
        ExportButton  matlab.ui.control.Button
    end

   
    properties (Access = private)
        Year  % Description
        Data
        SmoothedData % Description
    end
   

    methods (Access = private)

        % Button pushed function: LoadButton
        function LoadButtonPushed(app, event)
            S=webread("http://climatedataapi.worldbank.org/climateweb/rest/v1/country/cru/tas/year/USA");
            app.Year=[S.year];
            app.Data=[S.data];
            plot(app.UIAxes,[S.year],[S.data])
        end

        % Value changed function: Slider
        function SliderValueChanged(app, event)
            changingvalue = event.Value;
            app.SmoothedData = smooth(app.Data,changingvalue);
            plot(app.UIAxes,app.Year,app.Data)
            hold(app.UIAxes,'on')
            plot(app.UIAxes,app.Year,app.SmoothedData)
            hold(app.UIAxes,'off')
        end

        % Button pushed function: ExportButton
        function ExportButtonPushed(app, event)
           assignin('base','smoothedData',app.SmoothedData)
        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 LoadButton
            app.LoadButton = uibutton(app.UIFigure, 'push');
            app.LoadButton.ButtonPushedFcn = createCallbackFcn(app, @LoadButtonPushed, true);
            app.LoadButton.Position = [116 96 100 22];
            app.LoadButton.Text = 'Load ';

            % Create UIAxes
            app.UIAxes = uiaxes(app.UIFigure);
            title(app.UIAxes, 'Title')
            xlabel(app.UIAxes, 'X')
            ylabel(app.UIAxes, 'Y')
            app.UIAxes.Position = [32 263 300 185];

            % Create SliderLabel
            app.SliderLabel = uilabel(app.UIFigure);
            app.SliderLabel.HorizontalAlignment = 'right';
            app.SliderLabel.Position = [57 200 36 22];
            app.SliderLabel.Text = 'Slider';

            % Create Slider
            app.Slider = uislider(app.UIFigure);
            app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
            app.Slider.Position = [114 209 150 3];

            % Create ExportButton
            app.ExportButton = uibutton(app.UIFigure, 'push');
            app.ExportButton.ButtonPushedFcn = createCallbackFcn(app, @ExportButtonPushed, true);
            app.ExportButton.Position = [302 96 100 22];
            app.ExportButton.Text = 'Export';
        end
    end

    methods (Access = public)

        % Construct app
        function app = tutorGUI

            % 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
    end
end
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 剧情简介:自离婚之后,福斯特医生和儿子汤姆一度过着平静又有些沉闷的生活,—直至前夫西蒙的请柬飘然而至,他和女友凯特...
    81年漂于的深圳观察者阅读 557评论 0 0
  • 想着多睡一会儿的,没想到又是六点多醒来,生物钟真是一个可怕的东西。 昨天听孩子爸爸说碰到了一个老同学,看起来颇有些...
    公子赵阅读 140评论 0 1
  • “人生就像滚雪球,最重要的是发现很湿的雪和很长的坡”(巴菲特)。小长假重读曾国藩传(张宏杰著),第一章谈到他的人生...
    考拉老爹阅读 72评论 0 0
  • 大连梵高梦境星空馆,今天打卡啦! 总的来说非常梦幻,也可能是我之前一直没有去过此类的艺术馆,各种景物十分梦幻,可以...
    了黑阅读 197评论 0 1
  • 夜莺2517阅读 127,946评论 1 9

友情链接更多精彩内容