matlab gui assignin,2021-04-03 MatlabGUI

% 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值