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: <>
References: <hqqhm2$ipj$> <hqqjri$o43$> <hqqk8g$si$> <hqqlaf$hl2$> <hqqmke$kr8$> <hqqnit$mk2$>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: 1272470523 4420 (28 Apr 2010 16:02:03 GMT)
NNTP-Posting-Date: Wed, 28 Apr 2010 16:02:03 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: comp.soft-sys.matlab:630651

In article <hqqnit$mk2$>, 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.