Re: wavread, performance due to memory allocation
- From: "Steven Lord" <slord@xxxxxxxxxxxxx>
- Date: Thu, 1 Dec 2005 09:42:03 -0500
"Dan Ash" <dan_ash@xxxxxxxxxxxxx> wrote in message
news:1133421919.590740.280780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> This may be obvious to most of you, but in case it is not, thought I'd
> save someone some time. Or maybe I am the only idiot out here.
>
> I finally figured out why my scripts incorporating wavread() would
> stall.
*snip code that runs faster with preallocation*
Yes, this technique is known as preallocation. Rather than forcing MATLAB
to allocate more memory for a growing array each time through the FOR loop,
preallocation forces MATLAB to allocate memory once before the FOR loop, and
the FOR loop will fill up the allocated memory. This technique, as well as
a number of others, are described in the "Improving Performance and Memory
Usage" section of the MATLAB documentation:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch15_per.html#764852
It's the second technique listed for improving performance. You might also
want to see if the first technique, vectorizing your loop, is possible -- it
might help your code run faster.
Another section in the documentation, "Programming Tips", doesn't deal
directly with performance per se, but it does offer some best practices for
programming in MATLAB, which you may also find useful.
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch16_pro.html#57435
--
Steve Lord
slord@xxxxxxxxxxxxx
.
- References:
- wavread, performance due to memory allocation
- From: Dan Ash
- wavread, performance due to memory allocation
- Prev by Date: Viewshed & Line of Sight singularities?
- Next by Date: Associative Geometry
- Previous by thread: wavread, performance due to memory allocation
- Next by thread: Integrating a vector
- Index(es):
Relevant Pages
|