Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mexCallMATLAB populating inputs
Date: Fri, 28 Aug 2009 06:10:03 +0000 (UTC)
Organization: Boeing
Lines: 18
Message-ID: <h77sbr$p8s$1@fred.mathworks.com>
References: <70c8e2ce-c34a-454e-8c40-d186e7aa61b4@s6g2000vbp.googlegroups.com> <h6kpof$4oj$1@fred.mathworks.com> <h77k3d$bs4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1251439803 25884 172.30.248.38 (28 Aug 2009 06:10:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 28 Aug 2009 06:10:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:566671


"Ramana murthy" <omurthy@yahoo.com> wrote in message <h77k3d$bs4$1@fred.mathworks.com>...
> Hi James,
> 
> One small doubt.
> Suppose I call interp1.m (matlab in-built function) in mex file.
> Will it's Execution time be less than what if it were to be called in a matlab script file?
> with same data, of course.
> 
> I have one application (m file) where I am calling some 256x256x3 times the interp1.m function. If I send the data into mex routine and call interp1.m from mex file, compute and send the results back to m file, will it take less time? 
> 
> with regards,
> ramana

No. Passing the variable to a mex file and then calling interp1 with mexCallMATLAB is going to take the same amount of time as calling it directly from a script file ... you are calling the exact same function in either case. In general, any m-file called from a mex routine with mexCallMATLAB is going to take at least as long as calling the same m-file from a script file. In some cases it can even take longer, because an m-file called from a script is allowed to return a shared data copy, whereas the same m-file called from a mex routine with mexCallMATLAB is prevented from returning a shared data copy ... so extra work may have to be done for the same call from a mex routine. I suspect MATLAB enforces this for mexCallMATLAB to make sure there is no unintended data corruption downstream in the mex routine.

Situations where mex files shine is when there are a huge number of intermediate variables (matrix slices, etc.) that create a lot of overhead when coded in MATLAB, but all this overhead can potentially be saved by recoding the same algorithm in a mex routine. If the overhead is significant, the mex routine can significantly outperform the m-code.

James Tursa