Thread Subject: big arrays with variable dimension sizes

Subject: big arrays with variable dimension sizes

From: David Doria

Date: 16 Sep, 2007 20:04:14

Message: 1 of 4

I have a 4d array where sometimes dimension 3 is length 10
and sometimes dimension 3 is length 200.

When I do something like this:

Normalized_Moment_Values(1, 1, :, :), I usually do
squeeze(Normalized_Moment_Values(1, 1, :, :)) to give a
civilized looking result. However, in this case, i get
something that is LEN x 200, and if it happens to be a time
when it is only length 10, i get 190 rows of 0's. Is there
a better way to do this (to remove the 0's or even to store
the whole thing so that it doesn't fill the rest with 0's?)?

Thanks!!

David

Subject: big arrays with variable dimension sizes

From: David Doria

Date: 17 Sep, 2007 12:43:29

Message: 2 of 4

Is there no way to do this??

"David Doria" <daviddoria@gmail.com> wrote in message
<fck27u$88o$1@fred.mathworks.com>...
> I have a 4d array where sometimes dimension 3 is length 10
> and sometimes dimension 3 is length 200.
>
> When I do something like this:
>
> Normalized_Moment_Values(1, 1, :, :), I usually do
> squeeze(Normalized_Moment_Values(1, 1, :, :)) to give a
> civilized looking result. However, in this case, i get
> something that is LEN x 200, and if it happens to be a time
> when it is only length 10, i get 190 rows of 0's. Is there
> a better way to do this (to remove the 0's or even to store
> the whole thing so that it doesn't fill the rest with 0's?)?
>
> Thanks!!
>
> David

Subject: big arrays with variable dimension sizes

From: Simon Preston

Date: 17 Sep, 2007 13:48:08

Message: 3 of 4

"David Doria" <daviddoria@gmail.com> wrote in message
<fclsph$509$1@fred.mathworks.com>...
> Is there no way to do this??
>
> "David Doria" <daviddoria@gmail.com> wrote in message
> <fck27u$88o$1@fred.mathworks.com>...
> > I have a 4d array where sometimes dimension 3 is length 10
> > and sometimes dimension 3 is length 200.
> >
> > When I do something like this:
> >
> > Normalized_Moment_Values(1, 1, :, :), I usually do
> > squeeze(Normalized_Moment_Values(1, 1, :, :)) to give a
> > civilized looking result. However, in this case, i get
> > something that is LEN x 200, and if it happens to be a time
> > when it is only length 10, i get 190 rows of 0's. Is there
> > a better way to do this (to remove the 0's or even to store
> > the whole thing so that it doesn't fill the rest with 0's?)?
> >
> > Thanks!!
> >
> > David
>

You mean you want to store variable-length vectors in the
same array? A cell array will do this, see:

http://blogs.mathworks.com/loren/category/cell-arrays/

You can strip zeros using a logical argument, e.g. for
a = cat(1,rand(4,1),zeros(10,1))
then
a = a(a~=0)

Best wishes, S

Subject: big arrays with variable dimension sizes

From: Randy Poe

Date: 17 Sep, 2007 13:49:29

Message: 4 of 4

On Sep 16, 4:04 pm, "David Doria" <daviddo...@gmail.com> wrote:
> I have a 4d array where sometimes dimension 3 is length 10
> and sometimes dimension 3 is length 200.
>
> When I do something like this:
>
> Normalized_Moment_Values(1, 1, :, :), I usually do
> squeeze(Normalized_Moment_Values(1, 1, :, :)) to give a
> civilized looking result. However, in this case, i get
> something that is LEN x 200, and if it happens to be a time
> when it is only length 10, i get 190 rows of 0's. Is there
> a better way to do this (to remove the 0's or even to store
> the whole thing so that it doesn't fill the rest with 0's?)?

I'm not clear if you're trying to fix a display problem
or a storage problem, but perhaps you want to look
into cell arrays, which can have elements of arbitrary
length (in fact, of arbitrary dimension or type).

            - Randy

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com