|
Thanks for the reply. I think this is probably elegant enough, and it works!
I've also changed the subject, hopefully it can attract more eyeballs.
"Nasser M. Abbasi" <nma@12000.org> wrote in message <iqsb09$pfi$1@speranza.aioe.org>...
> On 5/16/2011 7:47 AM, Pinpress wrote:
> > Hi,
> >
> > I am trying to programmable access a multi-dimensional matrix. Specifically,
> > if X is of m-by-n-by-p (and so on), I would like to access the i_th dimension. If the 1st:
> >
> > Y = X(1, :, :);
> >
> > or the 3rd:
> >
> > Y = X(:,:, 2);
> >
> > The problem is that I need to use a variable to identify the i_th dimension.
> > I wonder how to most efficiently/elegantly do this.
> >
> > Thanks!
>
> You mean something like this?
>
> --------------------
> format short
> A=rand(2,2,2)
> r={':',':',':'};
>
> dimension=1;
> r{dimension}=dimension;
> C=A(r{:})
>
> dimension=2;
> r{dimension}=dimension;
> C=A(r{:})
> ----------------------
>
> --Nasser
|