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 次查看(过去 30 天)
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

采纳的回答

Mohammad Sami
Mohammad Sami 2022-4-1
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 个评论
Mohammad Sami
Mohammad Sami 2022-4-13
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by