Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Preallocating structures
Date: Tue, 17 Mar 2009 20:12:02 +0000 (UTC)
Organization: Mitre Corp
Lines: 24
Message-ID: <gpp06i$66n$1@fred.mathworks.com>
References: <gpovld$r76$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1237320722 6359 172.30.248.35 (17 Mar 2009 20:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Mar 2009 20:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2318
Xref: news.mathworks.com comp.soft-sys.matlab:525634

"Kian " <kian.torab@utah.edu> wrote in message <gpovld$r76$1@fred.mathworks.com>...
> I'm trying to preallocate structures, but I can't find any information on how to do this.
> 
> Here's what I have:
> 
> myStructure.Channels.Units.Trial
> 
> There should be 96 channels, 5 units, 100 trials, and then an array of spike times for each trial.
> 
> For example, myStructure.Channel(4).Unit(2).Trial(27)
> 
> should give me all the spike times that occurred on channel 4 by unit 2 and on the 27th trial.
> 
> I'd like to preallocate my structure so the code runs faster. I know how to preallocate a single simple structure: 
> 
> myStructure(10) = struct('fieldname', []);
> 
> Any idea?

% I believe if you simply use something like:

myStructure.Channel(4).Unit(2).Trial(27) = 0

% MATLAB will create and "preallocate" the myStructure array with all zeros.