Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: big arrays with variable dimension sizes
Date: Mon, 17 Sep 2007 13:48:08 +0000 (UTC)
Organization: University of Nottingham
Lines: 35
Message-ID: <fcm0io$3h1$1@fred.mathworks.com>
References: <fck27u$88o$1@fred.mathworks.com> <fclsph$509$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1190036888 3617 172.30.248.37 (17 Sep 2007 13:48:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 Sep 2007 13:48:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1072079
Xref: news.mathworks.com comp.soft-sys.matlab:428882



"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