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 "

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Mohammad Sami
Mohammad Sami le 1 Avr 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 commentaires
Mohammad Sami
Mohammad Sami le 13 Avr 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);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by