Converting double to a handle

164 visualizaciones (últimos 30 días)
DARLINGTON ETAJE
DARLINGTON ETAJE el 23 de Abr. de 2020
Comentada: Adam Danz el 28 de Nov. de 2022
When I run the app designer, I keep getting the error
Error setting property 'EditField' of class 'Name0fGui':
Cannot convert double value 2 to a handle
Here is the code
properties (Access = private)
counter1=0 % Description
counter2=0 % Description
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
value1=app.ChestPainCheckBox.Value;
if value1==1
app.counter1=app.counter1+1;
else
app.counter1=app.counter1;
end
value2=app.LuckyDipMaCheckBox.Value;
if value2==1
app.counter2=app.counter2+1;
else
app.counter2=app.counter2;
end
value3=app.AbrosyeCheckBox.Value;
if value3==1
app.counter1=app.counter1+1;
else
app.counter1=app.counter1;
end
value4=app.UnclemidadaCheckBox.Value;
if value4==1
app.counter2=app.counter2+1;
else
app.counter2=app.counter2;
end
app.EditField=app.counter1;
app.EditField2=app.counter2;
end
end
  2 comentarios
Maria Paula
Maria Paula el 28 de Nov. de 2022
Editada: Adam Danz el 28 de Nov. de 2022
When I run the app designer, I keep getting the error
Cannot convert double value NaN to a handle
Here is the code
classdef MetodoBiseccion < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
RaizAproximadaEditField matlab.ui.control.EditField
RaizAproximadaEditFieldLabel matlab.ui.control.Label
MetodoBiseccionLabel matlab.ui.control.Label
Calcular matlab.ui.control.Button
tol matlab.ui.control.NumericEditField
ToleranciaEditFieldLabel matlab.ui.control.Label
b matlab.ui.control.NumericEditField
ValordebLabel matlab.ui.control.Label
Funcion matlab.ui.control.EditField
FuncionEditFieldLabel matlab.ui.control.Label
a matlab.ui.control.NumericEditField
ValordeaLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
methods (Access = private)
end
methods (Access = public)
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Calcular
function CalcularButtonPushed(app, event)
i=app.a.Value;
y=app.Funcion.Value(i);
y(i);
app.a(i);
app.b(i);
if(str2double(app.Funcion.Value(app.a.Value))*str2double(app.Funcion.Value(app.b.Value))>0)
error('Nose cumple el Teorema del Valor Intermedio');
end
fa(i)=str2double(app.Funcion.Value(app.a.Value(i)));
fb(i)=str2double(app.Funcion.Value(app.b.Value(i)));
while(abs(app.b.Value-app.a.Value)>app.tol.Value)
if (fa(i)*fb(i)==0)
if (fa(i))==0
y(i)=app.a(i);
break
end
else
y(i)=(app.a.Value(i)+app.b.Value(i))/2;
fp(i)=str2double(app.Funcion.Value(num2str(y(i))));
end
if(fa(i)*fp(i)>0)
app.a(i+1)=y(i);
app.b(i+1)=app.b(i);
fa(i+1)=fp(i);
fb(i+1)=fb(i);
i=i+1;
else
app.a(i+1)=app.a(i);
app.b(i+1)=str2double(y(i)); % ERROR> Cannot convert double value NaN to a handle
fa(i+1)=fa(i);
fb(i+1)=fp(i);
i=i+1;
end
end
fprintf(' N a f(a) b f(b) p f(p)\n')
N=length(y);
for i= 1:N
fprintf('%4.1f %11.6f %11.6f %11.6f %11.6f %11.6f %11.6f\n',i,app.a(i),fa(i),app.b(i),fb(i),y(i),fp(i))
end
end
% Value changed function: Funcion
function FuncionValueChanged(app, event)
end
end
Adam Danz
Adam Danz el 28 de Nov. de 2022
There are a few lines of your code that looks like this
app.a(i+1)=y(i);
app.a is an object handle but you are trying to assign a value to the handle instead of assigning the value to the object's property. You probably mean app.a.Value(i) = y(i); There is >1 line of code that needs fixed so look carefully.
Also, this looks fishy for the same reason:
app.b(i+1)=app.b(i);

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 23 de Abr. de 2020
Try
app.EditField.Value = app.counter1;
app.EditField2.Value = app.counter2;
% ^^^^^^
If that doesn't fix the problem, please provide the entire error message and point to the line that is causing the error.
  4 comentarios
DARLINGTON ETAJE
DARLINGTON ETAJE el 24 de Abr. de 2020
Thank you Adam...you are a life saver...I celebrate you. When the isolation is over...please visit Calgary so I can bring you over for dinner with my family...
Adam Danz
Adam Danz el 24 de Abr. de 2020
Glad I could help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by