I have this function which takes a string as an input.
for example it takes handles.f = 'x^2'
but I want handles.f = x^2 so that later I'll be able to do f(x) = handles.f
function edit1_Callback(hObject, eventdata, handles)
handles.f = (get(hObject,'String'))
handles.f
area = rect(handles.f,handles.u,handles.l,handles.n)
guidata(hObject,handles)
Function:
function [ s ] = rect( f,u,l,n )
syms x;
f(x) = f;
h =(u-l)/n
z = l:h:u;
y = f(z)
s = 0;
for i=1:n
s = s+y(i);
end
s = h*s;
end
When i call this function from command prompt like this: rect(x^2,5,1,4)
It works fine But it gives error when I call this from gui.
This is the error I get:
Error using sym/subsindex (line 1558)
Indexing input must be numeric, logical or ':'.
Error in rect (line 8)
f(x) = f;