概述
% 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
最后
以上就是殷勤钢笔为你收集整理的matlab gui assignin,2021-04-03 MatlabGUI的全部内容,希望文章能够帮你解决matlab gui assignin,2021-04-03 MatlabGUI所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复