|
Hi,
You can directly evaluate the user string as far as all
inputs ("theta", "x"...) are in your current workspace...
For instance,
theta=[2 3];
a=1;
try
my_result=eval('theta(1)*x^2 - theta(2)*x^3');
catch
disp('Unable to evaluate user expression')
end
If the user expression is a simple matlab function, you can
then use "str2func" function.
regards, chris
"Nick Denman" <ngdenmanNOSPAM@gmail.REMOVETHIS.com> wrote
in message <frr1de$7a5$1@fred.mathworks.com>...
> Hi
>
> I have a GUI where the user can enter a function (as a
> string) that is evaluated in another routine. For example,
> the user may enter 'theta(1)*x^2 - theta(2)*x^3'.
>
> Currently I convert the above string expression to an
> anonymous function by using EVAL, e.g.
> >> fHnd = eval(['@(x,theta) (',str,')'])
> where str is the string given in the GUI. Can anyone
suggest
> a better way of creating the anonymous function without
> using eval?
>
> Cheers,
> Nick
|