help-octave
[Top][All Lists]
Advanced

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

Re: some multi-dimensional matrix problem


From: Bart Vandewoestyne
Subject: Re: some multi-dimensional matrix problem
Date: Mon, 24 May 2004 12:05:13 -0500
User-agent: Mutt/1.3.28i

On Mon, May 24, 2004 at 08:57:40AM -0400, Hall, Benjamin wrote:
> Another option is
> 
> squeeze(p)

Yes, i've used that, but squeeze starts filling columnwise, so i get a
result that is the transposed of what i really want.  I could transpose
it afterwards, but my guess was that this transpose operation also takes
some time, and I was wondering if there isn't a way to get my result
immediately row-wise.

Bart

>   Hi Bart,
> 
> something like:
> 
> octave:5> p = randn (1,3,4), res = reshape (p,3,4)
> p =
>  
> ans(:,:,1) =
>  
>   -0.56687   0.46960   1.76420
>  
> ans(:,:,2) =
>  
>   -0.62780   0.10564  -0.21290
>  
> ans(:,:,3) =
>  
>   -0.18718   0.34680   0.66555
>  
> ans(:,:,4) =
>  
>    0.523143  -0.486609   0.042819
>  
> res =
>  
>   -0.566865  -0.627797  -0.187179   0.523143
>    0.469599   0.105643   0.346800  -0.486609
>    1.764205  -0.212903   0.665555   0.042819
> 
>    Hth,
> 
>    Etienne
> 
> 
> 
> On Fri, May 21, 2004 at 04:02:30AM -0500, Bart Vandewoestyne wrote:
> # Suppose you had a multi-dimensional matrix p that looked like:
> # 
> # >> p
> # 
> # p(:,:,1) =
> # 
> #     0.8995    0.3137    0.2517    0.4330    0.8424
> # 
> # 
> # p(:,:,2) =
> # 
> #     0.1845    0.5082    0.4522    0.3256    0.3801
> # 
> # I'm sure from my calculations that p(:,:,x) is always a 1xN vector.
> # Now I want to combine all these 1xN vectors into a single result matrix,
> # and I'm currently doing it like this (M is the max last dimension of p):
> # 
> # for j=1:M,
> #   res(j,:) = p(:,:,j);
> # end
> # 
> # which gives me what i want, but I was wondering if there's a faster,
> # more vectorized way...
> # 
> # Thanks,
> # Bart

-- 
!!!!!!!!!!!!!!!!!!! email change !!!!!!!!!!!!!!!!!!!!
My email address is now address@hidden
        Please update your addressbook!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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