In Matlab App Designer UIAxes doesn´t graph anything.

3 views (last 30 days)
Hi Everyone, I have a problem with matlab app designer. I'm design a prototype of vibration transductor and i want to design an app to graph in real time the serial data of three axes (X, Y and Z). This serial data come from an ADXL345 and they send from a HC-06 for Arduino (the data are received on COM7).
The bluetooth module, connects correctly, because i configured it to turn on a Led that certified the connection, but The UIAxesX, UIAxesY and UIAxesZ, don't graph anything.
  2 Comments
Germán Ignacio
Germán Ignacio on 7 Nov 2023
@Voss I'm sorry, this is the complete code:
classdef Analisis < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ConectadoLamp matlab.ui.control.Lamp
ConectadoLampLabel matlab.ui.control.Label
StopButton matlab.ui.control.Button
StartButton matlab.ui.control.Button
ADQUISICIONDEDATOSLabel matlab.ui.control.Label
UIAxesZ matlab.ui.control.UIAxes
UIAxesY matlab.ui.control.UIAxes
UIAxesX matlab.ui.control.UIAxes
end
properties (Access = private)
vib % Description
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.vib = serialport("COM7", 9600);
configureTerminator(app.vib, "CR/LF");
app.UIAxesX.XLim = [0 1000];
app.UIAxesX.YLim = [0 3];
app.UIAxesY.XLim = [0 1000];
app.UIAxesY.YLim = [0 3];
app.UIAxesZ.XLim = [0 1000];
app.UIAxesZ.YLim = [0 3];
app.ConectadoLamp.Color = "blue";
end
% Button pushed function: StartButton
function StartButtonPushed(app, event)
app.ConectadoLamp.Color = "blue";
fopen(app.vib);
matX = zeros(1, 1000);
matY = zeros(1, 1000);
matZ = zeros(1, 1000);
co = 1;
% Inicializa los gráficos en el UIAxesX, UIAxesY y UIAxesZ
plot(app.UIAxesX, 1:co, matX(1:co), 'b');
plot(app.UIAxesY, 1:co, matY(1:co), 'r');
plot(app.UIAxesZ, 1:co, matZ(1:co), 'g');
while isvalid(app.UIFigure) && co <= 100
dataLine = fgetl(app.vib);
data = STR2DOUBLE(dataLine);
if length(data) == 3
matX(co) = data(1);
matY(co) = data(2);
matZ(co) = data(3);
% Actualiza los gráficos en tiempo real
plot(app.UIAxesX, 1:co, matX(1:co), 'b');
plot(app.UIAxesY, 1:co, matY(1:co), 'r');
plot(app.UIAxesZ, 1:co, matZ(1:co), 'g');
co = co + 1;
end
pause(0.1);
end
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 641 480];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxesX
app.UIAxesX = uiaxes(app.UIFigure);
title(app.UIAxesX, 'Eje X')
xlabel(app.UIAxesX, 'X')
ylabel(app.UIAxesX, 'Y')
app.UIAxesX.Position = [9 58 210 207];
% Create UIAxesY
app.UIAxesY = uiaxes(app.UIFigure);
title(app.UIAxesY, 'Eje Y')
xlabel(app.UIAxesY, 'X')
ylabel(app.UIAxesY, 'Y')
app.UIAxesY.Position = [218 58 208 207];
% Create UIAxesZ
app.UIAxesZ = uiaxes(app.UIFigure);
title(app.UIAxesZ, 'Eje Z')
xlabel(app.UIAxesZ, 'X')
ylabel(app.UIAxesZ, 'Y')
app.UIAxesZ.Position = [425 58 205 207];
% Create ADQUISICIONDEDATOSLabel
app.ADQUISICIONDEDATOSLabel = uilabel(app.UIFigure);
app.ADQUISICIONDEDATOSLabel.FontWeight = 'bold';
app.ADQUISICIONDEDATOSLabel.Position = [250 441 149 29];
app.ADQUISICIONDEDATOSLabel.Text = 'ADQUISICION DE DATOS';
% Create StartButton
app.StartButton = uibutton(app.UIFigure, 'push');
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.StartButton.Position = [64 381 100 23];
app.StartButton.Text = 'Start';
% Create StopButton
app.StopButton = uibutton(app.UIFigure, 'push');
app.StopButton.Position = [64 346 100 23];
app.StopButton.Text = 'Stop';
% Create ConectadoLampLabel
app.ConectadoLampLabel = uilabel(app.UIFigure);
app.ConectadoLampLabel.HorizontalAlignment = 'right';
app.ConectadoLampLabel.Position = [66 308 63 22];
app.ConectadoLampLabel.Text = 'Conectado';
% Create ConectadoLamp
app.ConectadoLamp = uilamp(app.UIFigure);
app.ConectadoLamp.Position = [144 308 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 = Analisis
% 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
THE MODULE IS CONNECTED CORRECTLY BUT THE DATA DOESN'T GRAPH.

Sign in to comment.

Answers (1)

Germán Ignacio
Germán Ignacio on 7 Nov 2023
Now i changed "STR2DOUBLE" for "str2num" and the X axe graph is ok, the other graphs, don´t received the data

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!