help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: preallocating memory for cell arrays


From: E. Joshua Rigler
Subject: Re: preallocating memory for cell arrays
Date: Fri, 05 Nov 2004 11:44:05 -0700

Actually, it was a "structure array" that I wanted in the first place,
but I couldn't figure out how to make one.  For instance, this certainly
doesn't work in 2.1.57:

  x=struct('test1',zeros(2));
  X=[x,x];

Using a cell array (i.e. X={x,x}) was just a stop-gap solution as far as
I was concerned, but I could find nothing in any of the documentation on
how to create an array of structures.

Then, as I was about to click send for this email, the obvious solution
hit me like a ton of bricks.  I'll share it here for all those who may
have been as dense as I about this particular problem:

  x=struct('test2',zeros(2));
  X(1:2) = x;
 
So, 1) is this the best solution; 2) does this actually preallocate all
the memory I will need; and 3) would the syntax "X=[x,x]" ever be
desirable (see first example above)?  Thanks.

-EJR


On Fri, 2004-11-05 at 10:40, John W. Eaton wrote:
> On  5-Nov-2004, E. Joshua Rigler <address@hidden> wrote:
> 
> | First, is there any way store a "time series" of structures other than
> | in a cell array?
> | 
> | Second, since I believe the answer to question #1 is "no", how would one
> | go about preallocating a cell array to hold a predetermined number of
> | similar structures.
> 
> What do you mean by "similar structures"?  Do they all have the same
> fields?  If so, then why not use a structure array?  Or maybe I'm not
> understanding what it is you are really trying to do?  Perhaps you
> could post an example of the code you would like to be able to write
> but can't because it doesn't work.
> 
> jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]