Help with error code for my GUI

I'm currently creating a GUI that is able to graph a user defined function. You are also able to find the zero value at a point by clicking a button that that then activates ginput. The code for this is below.
if true
% code
[x,y]=ginput(1);
fct=@(x) get(handles.funct,'String');
zero=num2str(fzero(fct,x));
set(handles.edit8,'String',zero);
guidata(hObject,handles)
end
In this code handles.funct is the user defined function, and handles.edit8 is a edit box where the answer will be output. Now when i run this program for a function such as 'cos(x)' i get the following error code as well as the edit box displaying NaN
if true
% code
Operands to the || and && operators must be
convertible to logical scalar values.
Error in fzero (line 308)
elseif ~isfinite(fx) || ~isreal(fx)
Error in Matlabfinalproject>findzero_Callback (line
186)
zero=num2str(fzero(fct,x));
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Matlabfinalproject (line 44)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Matlabfinalproject('findzero_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
end
Not having enough knowledge of how to debug this was wondering if anyone else could help me explain to me why i'm getting this code

2 comentarios

Niklas Nylén
Niklas Nylén el 11 de Abr. de 2014
What does the function fct look like? What is the value of x from ginput?
Stephen Hawkins
Stephen Hawkins el 16 de Abr. de 2014
the user defines fct as x.^3-tan(x)+20. and i'm trying to find a zero at 1

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 10 de Abr. de 2014

Comentada:

el 16 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by