Plotting in App designer

327 vues (au cours des 30 derniers jours)
Francesco Carraro
Francesco Carraro le 19 Fév 2020
Modifié(e) : VBBV le 24 Fév 2023
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
  1 commentaire
Eric Sargent
Eric Sargent le 9 Déc 2020
Modifié(e) : Eric Sargent le 9 Déc 2020

Connectez-vous pour commenter.

Réponse acceptée

Ajay Kumar
Ajay Kumar le 19 Fév 2020
x = 1:10;
y = sin(x);
plot(app.UIAxes,x,y);
  2 commentaires
Francesco Carraro
Francesco Carraro le 19 Fév 2020
Many Thanks
Niklas Kurz
Niklas Kurz le 6 Mar 2022
Awesome

Connectez-vous pour commenter.

Plus de réponses (2)

V.VENKATA
V.VENKATA le 6 Fév 2023
desin an app to find laplace transform of given signal and plot the laplace transform

VBBV
VBBV le 24 Fév 2023
Modifié(e) : VBBV le 24 Fév 2023
You need to add a callback function first to each of the components for graphs in which you want to plot. E.g.
%Callback to UIAxes
function Plot1(app,event) % corresponding to UIAxes chart
x = 1:10;
y = sin(x);
plot(app.UIAxes,x,y); % call/specify the handle to axess
end
%Callback to UIAxes2
function Plot2(app,event) % corresponding to UIAxes2 chart
x = 1:10;
y = sin(x);
plot(app.UIAxes2,x,y); % call/specify the handle to axes
end
Then use the corresponding axes handle to the plot function as above. Preferably, a pushbutton/s is required to generate the event for the desired callback function

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by