Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: avoid forloop
Date: Wed, 28 Apr 2010 12:02:03 -0400
Organization: The MathWorks
Lines: 18
Message-ID: <MPG.264226081090a8e9989ae0@news.mathworks.com>
References: <hqqhm2$ipj$1@fred.mathworks.com> <hqqjri$o43$1@fred.mathworks.com> <hqqk8g$si$1@fred.mathworks.com> <hqqlaf$hl2$1@fred.mathworks.com> <hqqmke$kr8$1@canopus.cc.umanitoba.ca> <hqqnit$mk2$1@fred.mathworks.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1272470523 4420 172.31.57.214 (28 Apr 2010 16:02:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 28 Apr 2010 16:02:03 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:630651

In article <hqqnit$mk2$1@fred.mathworks.com>, 
juliette.physicist@gmail.com says...
> Gotchya!
> So I guess this is one of those cases where the forloop is the best way (that is, if the arbitrary function cannot be vectorized like Matt and Roger did to mat2num above).
> 
> Thanks!
> 

if the function can be arbitrary, then you probably have no choice but 
to use a for loop at least sometimes.  You could, within try-catch, try 
a vectorized call, and only bail out to a for loop if that didn't work.  
If you DO use a for loop, you are far better off preallocating the 
output array b first rather than growing it in the loop.

-- 
Loren
http://blogs.mathworks.com/loren
http://matlabwiki.mathworks.com/MATLAB_FAQ