Error using plot Conversion to double from function_handle is not possible.

i have been trying to figure out whats happening with my code. Im trying to make a Plotter with GUI but there is a problem when it compiles just exactly at the plot command line the code is the next one:
function pushbutton1_Callback(hObject, eventdata, handles)
y=str2func(get(handles.fdy, 'String'))
x=linspace(0,100,1000);
plot(x,y)
fdy: Is the callback from the edit text where you have to insert the function Example= sin(x) As simply as that, i dont really know whats the problem it shows "Error using plot Conversion to double from function_handle is not possible." i dont know if its a variable type problem maybe i have to use str2func, but i tried and i dont know. Please help me out

 Risposta accettata

y is a function_handle, so you have to pass it some data.
plot(x,y(x))
What you did was basically equivalent to this:
plot(x,sin)

1 Commento

i did that:
x=linspace(0,100,1000);
y=str2func(get(handles.fdy, 'String'))
plot(x,y(x))
As a detail i will say that when i insert a function from fdy callback, for example: x-3 using str2func then it shows in console as y=@x-3 is that a properly statement? , cuz i dont know if i can use that as a real function.
But now when i compile that code i get a different error: Undefined function 'x-3' for input arguments of type 'double'.
and then it shows the line where is suposed to be this command plot(x,y(x))
This is a Copy Paste of my Console running fdy with x-3
Warning: The input to STR2FUNC "x-3" is not a valid function name. This will generate an error in a future release. > In grafiqueitor>pushbutton1_Callback at 108 In gui_mainfcn at 96 In grafiqueitor at 42 In @(hObject,eventdata)grafiqueitor('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
y =
@x-3
Undefined function 'x-3' for input arguments of type 'double'.
Error in grafiqueitor>pushbutton1_Callback (line 109) plot(x,y(x))
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in grafiqueitor (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)grafiqueitor('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Maybe you can find clues there. Thanks!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by