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 (최근 30일)
이전 댓글 표시
Pablo Manuel Torres Hernandez
2022년 3월 31일
댓글: Pablo Manuel Torres Hernandez
2022년 4월 13일
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
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!