COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

Is this the best way to store my data?

• Email
• Follow

```I'm trying to determine the optimal manner in which to store my data with regard to both memory usage and speed in MATLAB.  I'm considering an array of structures that contain a single array.  For example:

frame(1).data = [];
frame(2).data = [];
....
frame(N).data = [];

The 'data' will be size 3xM where M is not known in advance.  The reason I'm putting the "data" in a structure is that M will be different for each frame (sometimes M=0).

If I do this I have a couple questions:
1. How to I declare the size of frame initially so I'm not dynamically changing its size?  N is known.
2. Will MATLAB require a continuous block of memory for everything or only each data array?
3. I'll have to dynamically change the sizes of the individual data arrays.  Does doing this inside this structure incur more performance penalties than a regular stand-alone array would?

More importantly, is there a better way to do this?

Thanks!
```
 0
Reply CSB 4/7/2010 7:33:07 PM

See related articles to this posting

```On Apr 8, 7:33=A0am, "CSB" <cbrund...@hotmail.com> wrote:
> I'm trying to determine the optimal manner in which to store my data with=
regard to both memory usage and speed in MATLAB. =A0I'm considering an arr=
ay of structures that contain a single array. =A0For example:
>
> frame(1).data =3D [];
> frame(2).data =3D [];
> ...
> frame(N).data =3D [];
>
> The 'data' will be size 3xM where M is not known in advance. =A0The reaso=
n I'm putting the "data" in a structure is that M will be different for eac=
h frame (sometimes M=3D0).
>
> If I do this I have a couple questions:
> 1. How to I declare the size of frame initially so I'm not dynamically ch=
anging its size? =A0N is known.
> 2. Will MATLAB require a continuous block of memory for everything or onl=
y each data array?
> 3. I'll have to dynamically change the sizes of the individual data array=
s. =A0Does doing this inside this structure incur more performance penaltie=
s than a regular stand-alone array would?
>
> More importantly, is there a better way to do this?
>
> Thanks!

1. You don't need to.
2.  Only each data array
3.  No

What you propose is the way I'd do it myself.

```
 0
Reply TideMan 4/7/2010 9:37:34 PM

```CSB wrote:
> I'm trying to determine the optimal manner in which to store my data
> with regard to both memory usage and speed in MATLAB.  I'm considering
> an array of structures that contain a single array.  For example:
>
> frame(1).data = [];
> frame(2).data = [];
> ...
> frame(N).data = [];
>
> The 'data' will be size 3xM where M is not known in advance.  The reason
> I'm putting the "data" in a structure is that M will be different for
> each frame (sometimes M=0).
>
> If I do this I have a couple questions:
> 1. How to I declare the size of frame initially so I'm not dynamically
> changing its size?  N is known.

frame = struct('data', cell(N,1));

> More importantly, is there a better way to do this?

framedata = cell(N,1);

This will avoid one level of indirection that does not appear to be adding any
value to your task, at least not as described.
```
 0
Reply Walter 4/7/2010 9:48:38 PM

```Walter Roberson <roberson@hushmail.com> wrote in message <hpiujp\$54h\$1@canopus.cc.umanitoba.ca>...
> CSB wrote:
> > I'm trying to determine the optimal manner in which to store my data
> > with regard to both memory usage and speed in MATLAB.  I'm considering
> > an array of structures that contain a single array.  For example:
> >
> > frame(1).data = [];
> > frame(2).data = [];
> > ...
> > frame(N).data = [];
> >
> > The 'data' will be size 3xM where M is not known in advance.  The reason
> > I'm putting the "data" in a structure is that M will be different for
> > each frame (sometimes M=0).
> >
> > If I do this I have a couple questions:
> > 1. How to I declare the size of frame initially so I'm not dynamically
> > changing its size?  N is known.
>
> frame = struct('data', cell(N,1));
>
> > More importantly, is there a better way to do this?
>
> framedata = cell(N,1);
>
> This will avoid one level of indirection that does not appear to be adding any
> value to your task, at least not as described.

Yes, that does appear to meet my requirements as well but I did just a couple quick experiments and the memory usage seems to be about the same but the performance  is a little better when I don't have to deal with cells even though, as you point out, there is an additional level of indirection.

Thanks to both of you for your quick responses.
```
 0
Reply CSB 4/8/2010 8:33:05 AM

3 Replies
386 Views

Similar Articles

12/8/2013 4:22:20 AM
page loaded in 93055 ms. (0)