Help with error code for my GUI
2 views (last 30 days)
Show older comments
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 Comments
Niklas Nylén
on 11 Apr 2014
What does the function fct look like? What is the value of x from ginput?
Answers (0)
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!