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 个评论

What does the function fct look like? What is the value of x from ginput?
the user defines fct as x.^3-tan(x)+20. and i'm trying to find a zero at 1

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by