Converting double to a handle
72 次查看(过去 30 天)
显示 更早的评论
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 个评论
Maria Paula
2022-11-28
编辑:Adam Danz
2022-11-28
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
2022-11-28
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);
采纳的回答
Adam Danz
2020-4-23
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Custom UI Components 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!