From: "Steven Lord" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: objects containing functions
Date: Mon, 29 Mar 2010 13:53:13 -0400
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <hoqpdm$nq9$>
References: <hoqo8l$4vl$>
Reply-To: "Steven Lord" <>
X-Trace: 1269885174 24393 (29 Mar 2010 17:52:54 GMT)
NNTP-Posting-Date: Mon, 29 Mar 2010 17:52:54 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: comp.soft-sys.matlab:621598

"Simon Preston" <> wrote in message 
> Hi all,
> I would like to represent a dynamical model (defined in terms of ODEs, 
> i.e., dx_dt = f(x,t;theta)) as a Matlab object.  To do so, I would like 
> the object to contain the function f as a property.
> One way to achieve this is to define f as an inline function.  The trouble 
> doing this is that solving the model with an ODE solver requires repeated 
> evaluations of this inline function, which is extemely slow.
> I could of course have f as a function separate from my model object, but 
> this loses the nice convenient and tidy property that the model object is 
> self contained.
> Any suggestions how I could do this better - i.e. ways of defining f 
> within the object, but so it is as fast to evaluate as if it were a 
> separate function?

Use a function handle.

Steve Lord
comp.soft-sys.matlab (CSSM) FAQ: