From: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Cell-Array preallocation slows code down
Date: Wed, 28 Nov 2012 22:16:19 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 19
Message-ID: <k962fj$c0o$>
References: <k78fae$gfp$>
Reply-To: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1354140979 12312 (28 Nov 2012 22:16:19 GMT)
NNTP-Posting-Date: Wed, 28 Nov 2012 22:16:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: comp.soft-sys.matlab:783756

"Vincent" wrote in message <k78fae$gfp$>...
> I created an object containing two cell-Arrays. These cell-Arrays will be filled with file contents. I do know how many rows the cell results in, however I can only estimate the columns.
> As I read in the help topics, preallocation could speed up my code. So I tried it and these are the results after profiling during the data insertion
> Without preallocation: 0.4 ms
> With row-preallocation: 9 ms
> With row and estimated column-preallocation: 95 ms
> How is this even possible? I'd like to optimize my code further. I could even assign the datatype for the cell-Array (char) - can I use this information?

Try out the different alternatives to preallocation mentioned in the following articles:

Yair Altman