Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <hoqo8l$4vl$1@fred.mathworks.com> <hoqpdm$nq9$1@fred.mathworks.com> <hosfka$gv8$1@fred.mathworks.com> <hosr04$ss2$1@fred.mathworks.com> <hot491$brj$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1270644022 9263 172.30.248.38 (7 Apr 2010 12:40:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 7 Apr 2010 12:40:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1072079
Xref: news.mathworks.com comp.soft-sys.matlab:624226

"Simon Preston" <preston.simon+mathsworks@gmail.com> wrote in message <hot491$brj$1@fred.mathworks.com>...
> "Rob Campbell" <matlab@robertREMOVEcampbell.removethis.co.uk> wrote in message <hosr04$ss2$1@fred.mathworks.com>...
> > 
> > > 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