MATLAB Answers

Plotting in App designer

56 views (last 30 days)
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".
classdef App1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure % UI Figure
UIAxes matlab.ui.control.UIAxes % Telemetria
UIAxes2 matlab.ui.control.UIAxes % Telemetria
LabelEditField matlab.ui.control.Label % Throttle
EditField matlab.ui.control.EditField % ------
LabelEditField2 matlab.ui.control.Label % F.Brake
EditField2 matlab.ui.control.EditField % -----
Slider matlab.ui.control.Slider % [0 100]
UIAxes3 matlab.ui.control.UIAxes % Track Map
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
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';
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.Position = [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
function app = App1()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
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 Comments

Sign in to comment.

Accepted Answer

Ajay Kumar
Ajay Kumar on 19 Feb 2020
x = 1:10;
y = sin(x);
plot(app.UIAxes,x,y);

  1 Comment

Sign in to comment.

More Answers (0)

Products


Release

R2016a