From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: objects containing functions
Date: Wed, 7 Apr 2010 12:40:22 +0000 (UTC)
Organization: University of Nottingham
Lines: 17
Message-ID: <hphufm$91f$>
References: <hoqo8l$4vl$> <hoqpdm$nq9$> <hosfka$gv8$> <hosr04$ss2$> <hot491$brj$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1270644022 9263 (7 Apr 2010 12:40:22 GMT)
NNTP-Posting-Date: Wed, 7 Apr 2010 12:40:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1072079
Xref: comp.soft-sys.matlab:624226

"Simon Preston" <> wrote in message <hot491$brj$>...
> "Rob Campbell" <> wrote in message <hosr04$ss2$>...
> > 
> > > Steve's suggestion to use function handles gives a big improvement over inline.  However, for my function f to be contained within the object, (I think) I need to use an anonymous function - I have tried this, and it runs slower by a factor of 2 compared with calling a function defined in the standard way.  Why is this and can it be avoided?
> > 
> > I don't know why that would be the case. 
> > Have you tried having your "fn(t,x,theta)" be an object method?
> Rob, thanks for the suggestion - though the f really needs to be a property of the object, so can't be hard-coded as a method.
> Interestingly there doesn't seem to be such difference in run times when the function output is scalar (rather than vector).  Not sure if maybe this gives a clue as to the source of slowness.
> Best wishes, S

Sorry for the bump, but can anybody (Steve maybe?) explain the reasons for anonymous functions being slower compare with a standard function defined in an m-file.  I.e. what are the relative overheads, what factors do they depend on and and how do the overheads scale with these factors?

Many thanks, S