I have created a matlab GUI in which a user selects a variable to integrate with respect to, inputs the equation, and lower and upper limits. When my code goes to calculate the integral on pushbutton Callback, I get an error I don't understand.
This is the line of code causing the error:
i1 = int( eval(get(handles.edit1,'string')),
(handles.respectvar),
get(handles.edit3),
get(handles.edit2)
);
%respactvar is the user-selected variable, and edit3 and edit2 are the lower and upper limits.
And this is the error message:
Error using sym>tomupad (line 1135) Conversion to 'sym' from 'struct' is not possible.
Error in sym (line 151) S.s = tomupad(x);
Error in sym/int (line 142) b = sym(b);
Error in projectCALC>pushbutton1_Callback (line 376) i1=int(eval(get(handles.edit1,'string')),(handles.respectvar),get(handles.edit3),get(handles.edit2));
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in projectCALC (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)projectCALC('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Thank you!
get(handles.edit3)
will just return a structure of the properties of the object. – excazaeval
is inefficient and unsafe, especially if you're evaluating something that the user input in the box. What if it's asystem
call? Are you sure you can't avoid usingeval
? – Andras Deakeval
for this kind of thing. I'm almost positivestr2func
is just a wrapper foreval
but I don't have MATLAB available to check. – excazastr2func
could be used instead ofeval
in many cases, suggesting that it's better. And on R2012bstr2func('system(''echo oops!'')')
will issue a warning (to be an error in a future release) and not execute the command (OK, of coursestr2func('@() system(''echo oops!'')')
can be evaluated byint
to cause harm still). Also,str2func
is a compiled built-in. – Andras Deak