Plotting in App designer

721 views (last 30 days)
Francesco Carraro
Francesco Carraro on 19 Feb 2020
Commented: Niklas Kurzon 6 Mar 2022
Hello everyone,
I just started using AppDesigner, and I don't know how to plot a function inside a "UIAxes" graph. I created this figure using the items in the component library, but once I switch in the "Code view" mode, I don't know how and where to add strings code to plot the function. To start I would plot a simple function as "sin(x)" in the selected "UIAxes".
classdefApp1 < matlab.apps.AppBase
% Properties that correspond to app components
properties(Access = public)
UIFigurematlab.ui.Figure% UI Figure
UIAxesmatlab.ui.control.UIAxes% Telemetria
UIAxes2matlab.ui.control.UIAxes% Telemetria
LabelEditFieldmatlab.ui.control.Label% Throttle
EditFieldmatlab.ui.control.EditField% ------
LabelEditField2matlab.ui.control.Label% F.Brake
EditField2matlab.ui.control.EditField% -----
Slidermatlab.ui.control.Slider% [0 100]
UIAxes3matlab.ui.control.UIAxes% Track Map
end
methods(Access = private)
% Code that executes after component creation
functionstartupFcn(app)
end
end
% App initialization and construction
methods(Access = private)
% Create UIFigure and components
functioncreateComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name ='UI Figure';
setAutoResize(app, app.UIFigure, true)
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes,'Telemetria');
app.UIAxes.Box ='on';
app.UIAxes.XGrid ='on';
app.UIAxes.YGrid ='on';
app.UIAxes.Position = [0 279 373 185];
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2,'Telemetria');
app.UIAxes2。Box ='on';
app.UIAxes2。XGrid ='on';
app.UIAxes2。YGrid ='on';
app.UIAxes2。位置= [23 45 604 226];
% Create LabelEditField
app.LabelEditField = uilabel(app.UIFigure);
app.LabelEditField.HorizontalAlignment ='right';
app.LabelEditField.FontSize = 10;
app.LabelEditField.Position = [546 233 35 15];
app.LabelEditField.Text ='Throttle';
% Create EditField
app.EditField = uieditfield(app.UIFigure,'text');
app.EditField.Position = [586 230 31 20];
app.EditField.Value ='------';
% Create LabelEditField2
app.LabelEditField2 = uilabel(app.UIFigure);
app.LabelEditField2.HorizontalAlignment ='right';
app.LabelEditField2.FontSize = 10;
app.LabelEditField2.Position = [546 209 36 15];
app.LabelEditField2.Text ='F.Brake';
% Create EditField2
app.EditField2 = uieditfield(app.UIFigure,'text');
app.EditField2.Position = [586 206 28 20];
app.EditField2.Value ='-----';
% Create Slider
app.Slider = uislider(app.UIFigure);
app.Slider.MajorTickLabels = {'','','','','',''};
app.Slider.Position = [51 33 566 3];
% Create UIAxes3
app.UIAxes3 = uiaxes(app.UIFigure);
title(app.UIAxes3,'Track Map');
app.UIAxes3.Position = [397 298 230 166];
end
end
methods(Access = public)
% Construct app
functionapp = App1()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
ifnargout == 0
clearapp
end
end
% Code that executes before app deletion
functiondelete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Accepted Answer

Ajay Kumar
Ajay Kumar on 19 Feb 2020
x = 1:10;
y = sin(x);
plot(app.UIAxes,x,y);
2 Comments
Niklas Kurz
Niklas Kurz on 6 Mar 2022
Awesome

Sign in to comment.

More Answers (0)

下载188bet金宝搏


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!