|
"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
|