help-octave
[Top][All Lists]

## Re: confused about how to define a cell array of vectors

 From: DushanM Subject: Re: confused about how to define a cell array of vectors Date: Thu, 15 Nov 2007 11:18:49 -0700 User-agent: MacSOUP/2.8.1 (Mac OS X version 10.4.10 (x86))

```James Sherman Jr. <address@hidden> wrote:

> I'm a bit confused, and maybe others are too.  Why can't you simply
> write a for loop like:
>
> CA = cell(size(X));
> for m = 1:size(X,1),
>  for n = 1:size(X,2),
>   CA{m,n} = [X(m,n), Y(m,n), Z(m,n)];
>  end
> end
>
> Is there something I'm missing?

Sorry, I forgot to mention this.  Yes, the 'for' loops are an obvious
way to do it.  What I was wondering is if there is a straightforward
vectorized way to do this.  If the index limits are modest (and I'm not
sure what upper value 'modest' may have in this context) the time cost
of the 'for' loops is unimportant, but for large limits it could become
significant.  In that case, is there a way of avoiding the 'for' loops?

- Dushan

> On Nov 15, 2007 3:40 AM, DushanM <address@hidden> wrote:
> > I've still not puzzled this out, and my earlier question about it didn't
> > get a response, so I'm trying again.  Maybe rephrasing will help.
> >
> > I have a 2-D, curved grid of points, indexed by (m,n).  The (x,y,z) com-
> > ponents of each point can be computed, giving three 2-arrays X, Y, and Z
> > so that X(m,n) is the x-component of the (m,n) point, etc.  What I would
> > now like to do, but don't know how, is define a 2-D cell array CA with
> > each cell a 3-vector: CA{m,n} = [ X(m,n); Y(m,n); Z(m,n) ].
> >
> > Could someone please point me to how to do this, or to where I can find
> > out?  Thanks.
> >
> > - Dushan Mitrovich
> > _______________________________________________
> > Help-octave mailing list