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 件のコメント

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

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2014 年 4 月 10 日

コメント済み:

2014 年 4 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by