Hi, everyone! I got an error while runnig this code . ""Error setting property 'AlturaactualEditField' of class 'app2': Cannot convert double value 3.79215 to a handle "

1 visualización (últimos 30 días)
Im trying to show on a EitField in AppDesigner values capture by a ultrasonic sensor in real time. I've al ready plotted in real time in axes, but when i try to show those values on a editField i got this error : "Error setting property 'AlturaactualEditField' of class 'app2':
Cannot convert double value 3.79215 to a handle"
Heres the code:
properties (Access = private)
ComunicacionSerial % Description
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.ComunicacionSerial=serial('COM3','BaudRate',9600,'Terminator','CR/LF');
app.ConectLamp.Color='red';
app.desconectLamp.Color='red';
end
% Button pushed function: ConectarButton
function ConectarButtonPushed(app, event)
app.ConectLamp.Color='green';
fopen(app.ComunicacionSerial);
matv=zeros(1,100);
math=zeros(1,100);
for cont=1:1:3000
sen=str2double(fscanf(app.ComunicacionSerial));
matv(cont)= sen(1)*5/1024;
math(cont)=(400*matv(cont)/58.2);
plot(app.UIAxes2,matv);
plot(app.UIAxes,math);
drawnow;
app.AlturaactualEditField= math(cont); %%Here´s the line where i got that error message
end
end
% Button pushed function: DesconectarButton
function DesconectarButtonPushed(app, event)
app.ConectLamp.Color='red'
app.desconectLamp.Color='green'
fclose(app.ComunicacionSerial);
clear all;
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
delete(app);
fclose(app.ComunicacionSerial);
delete(app.ComunicacionSerial);
end
end

Respuesta aceptada

Mohammad Sami
Mohammad Sami el 1 de Abr. de 2022
You need to assign it to the value of editfield rather then the edit field itself
app.AlturaactualEditField.Value = math(cont);
% or convert to string if its a text edit field
app.AlturaactualEditField.Value = string(math(cont));
  3 comentarios
Mohammad Sami
Mohammad Sami el 13 de Abr. de 2022
This means that you are using a numeric edit field. Therefore you do not require to convert your value to string first. You can directly assign the double variable to a numeric edit field.
app.AlturaactualEditField.Value = math(cont);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by