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 日間)
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);
Pablo Manuel Torres Hernandez
Pablo Manuel Torres Hernandez 2022 年 4 月 13 日
You were rigth , thank you so much !!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by