Path: news.mathworks.com!not-for-mail
From: "Nick Denman" <ngdenmanNOSPAM@gmail.REMOVETHIS.com>
Newsgroups: comp.soft-sys.matlab
Subject: Anonymous function creation from string
Date: Wed, 19 Mar 2008 12:37:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <frr1de$7a5$1@fred.mathworks.com>
Reply-To: "Nick Denman" <ngdenmanNOSPAM@gmail.REMOVETHIS.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205930222 7493 172.30.248.35 (19 Mar 2008 12:37:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 19 Mar 2008 12:37:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 745609
Xref: news.mathworks.com comp.soft-sys.matlab:458029



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