how to create an array of plots in App designer

15 Ansichten (letzte 30 Tage)
ahmed abdel razik
ahmed abdel razik am 11 Jul. 2021
I am using Matlab2019b and i am trying to create a real time plots, the number of plots displayed, depends on the user input parameters, so i defined a property
H_PLOT
;
then i created a for loop when a pushbutton is pressed
for i=1:1:app.num_of_channels
figure;
app.H_PLOT(1:app.num_of_channels) = plot(nan,nan, 'b');
end
but it gives me the following error:
"Assignment between unlike types is not allowed."
i dont understand why however it works well in normal m-code script but it doesnt work in app designer
  4 Kommentare
Walter Roberson
Walter Roberson am 13 Jul. 2021
It is not clear that you did
properties (Access = private)
H_PLOT; % Description
end
ahmed abdel razik
ahmed abdel razik am 14 Jul. 2021
Bearbeitet: ahmed abdel razik am 14 Jul. 2021
Here is the full code:
classdef PLOT_ARRAY < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
NEditFieldLabel matlab.ui.control.Label
NEditField matlab.ui.control.NumericEditField
LampLabel matlab.ui.control.Label
Lamp matlab.ui.control.Lamp
end
properties (Access = private)
TIME_STEP = 1 % fixed time step of calling SendData function
t % timer (for update GUI and send data)
timer = 0;
GREEN_COLOR = [0 1 0]
RED_COLOR = [1 0 0]
BLACK_COLOR = [0 0 0]
Trig = 0;
index = 1;
ref = 1;
N = 0;
h;
end
properties (Access = public)
H_PLOT; % DescriptionH_PLOT; % Description
end
methods (Access = private)
function timerFunction(app, ~, ~)
if(app.Trig)
app.Lamp.Color = app.BLACK_COLOR;
app.Trig = 0;
else
app.Lamp.Color = app.GREEN_COLOR;
app.Trig = 1;
end
for i=1:1:app.N
app.H_PlOT.XData(1:app.index) = 1:app.index;
app.H_PlOT.YData(1:app.index) = 1:app.index;
end
drawnow;
app.index = app.index + 1;
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.t = timer;
app.t.TimerFcn = @app.timerFunction;
app.t.ExecutionMode = 'fixedRate';
app.t.Period = app.TIME_STEP;
app.t.BusyMode = 'drop';
end
% Button pushed function: Button
function ButtonPushed(app, event)
app.N = app.NEditField.Value;
for i=1:1:app.N
figure;
app.H_PLOT = plot(nan,nan, 'b');
end
start(app.t);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [237 272 100 22];
% Create NEditFieldLabel
app.NEditFieldLabel = uilabel(app.UIFigure);
app.NEditFieldLabel.HorizontalAlignment = 'right';
app.NEditFieldLabel.Position = [197 325 25 22];
app.NEditFieldLabel.Text = 'N';
% Create NEditField
app.NEditField = uieditfield(app.UIFigure, 'numeric');
app.NEditField.Position = [237 325 100 22];
% Create LampLabel
app.LampLabel = uilabel(app.UIFigure);
app.LampLabel.HorizontalAlignment = 'right';
app.LampLabel.Position = [267 230 35 22];
app.LampLabel.Text = 'Lamp';
% Create Lamp
app.Lamp = uilamp(app.UIFigure);
app.Lamp.Position = [317 230 20 20];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = PLOT_ARRAY
% Create UIFigure and 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 23 Jul. 2021
In the lines
app.H_PlOT.XData(1:app.index) = 1:app.index;
app.H_PlOT.YData(1:app.index) = 1:app.index;
You are referring to H_PlOT instead of to H_PLOT . That is, you are using lower-case L instead of upper-case L.
  3 Kommentare
Walter Roberson
Walter Roberson am 23 Jul. 2021
What sequence of events or commands are you using to get that? I tried it and just got a blinking light.
ahmed abdel razik
ahmed abdel razik am 23 Jul. 2021
I just run this code, set the number to 3 and press the button
classdef PLOT_ARRAY < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
NEditFieldLabel matlab.ui.control.Label
NEditField matlab.ui.control.NumericEditField
LampLabel matlab.ui.control.Label
Lamp matlab.ui.control.Lamp
end
properties (Access = private)
TIME_STEP = 1 % fixed time step of calling SendData function
t % timer (for update GUI and send data)
timer = 0;
GREEN_COLOR = [0 1 0]
RED_COLOR = [1 0 0]
BLACK_COLOR = [0 0 0]
Trig = 0;
index = 1;
ref = 1;
N = 0;
h;
end
properties (Access = public)
H_PLOT; % DescriptionH_PLOT; % Description
end
methods (Access = private)
function timerFunction(app, ~, ~)
if(app.Trig)
app.Lamp.Color = app.BLACK_COLOR;
app.Trig = 0;
else
app.Lamp.Color = app.GREEN_COLOR;
app.Trig = 1;
end
for i=1:1:app.N
app.H_PLOT(i).XData(1:app.index) = 1:app.index;
app.H_PLOT(i).YData(1:app.index) = 1:app.index;
end
drawnow;
app.index = app.index + 1;
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.t = timer;
app.t.TimerFcn = @app.timerFunction;
app.t.ExecutionMode = 'fixedRate';
app.t.Period = app.TIME_STEP;
app.t.BusyMode = 'drop';
end
% Button pushed function: Button
function ButtonPushed(app, event)
app.N = app.NEditField.Value;
for i=1:1:app.N
figure;
app.H_PLOT(i) = plot(nan,nan, 'b');
end
start(app.t);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [237 272 100 22];
% Create NEditFieldLabel
app.NEditFieldLabel = uilabel(app.UIFigure);
app.NEditFieldLabel.HorizontalAlignment = 'right';
app.NEditFieldLabel.Position = [197 325 25 22];
app.NEditFieldLabel.Text = 'N';
% Create NEditField
app.NEditField = uieditfield(app.UIFigure, 'numeric');
app.NEditField.Position = [237 325 100 22];
% Create LampLabel
app.LampLabel = uilabel(app.UIFigure);
app.LampLabel.HorizontalAlignment = 'right';
app.LampLabel.Position = [267 230 35 22];
app.LampLabel.Text = 'Lamp';
% Create Lamp
app.Lamp = uilamp(app.UIFigure);
app.Lamp.Position = [317 230 20 20];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = PLOT_ARRAY
% Create UIFigure and 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by