help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: James Sherman Jr.
Subject: Re: confused about how to define a cell array of vectors
Date: Thu, 15 Nov 2007 13:43:44 -0500

So, I think this is what you're looking for:
Let X, Y and Z be size m,n.  Then make the matrix W, such that
W(1:m:3*m,:) = X;
W(2:m:3*m,:) = Y;
W(3:m:3*m,:) = Z;
Then you can use mat2cell:
CA = mat2cell(W, 3*ones(1,m), ones(1,n));

I think this is what you're shooting for.


On Nov 15, 2007 1:18 PM, DushanM <address@hidden> wrote:
> 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
> > > address@hidden
> > > https://www.cae.wisc.edu/mailman/listinfo/help-octave
> > >
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]