From bug-octave-request at bevo dot che dot wisc dot edu Sun Dec 21 12:54:25 2003 Subject: Re: Missing ND array functionality From: Quentin Spencer To: bug-octave at bevo dot che dot wisc dot edu Date: Sun, 21 Dec 2003 12:53:42 -0600 John W. Eaton wrote: >On 20-Dec-2003, Quentin Spencer wrote: > >| If you have a 3 dimensional array of size (x,y,z), there is not >| currently a function to "rotate" the dimensions to convert the array to >| an array of size (y,z,x) (such a conversion in two dimensions would be >| the same as a transpose). Matlab provides the function "shiftdim" to >| accomplish this. I think this may be possible using reshape as well. > >We have permute and ipermute. Can shiftdim be based on that? > > > Thanks for pointing those out. Yes, shiftdim can be based partially on that. For positive arguments, shiftdim would look like this: function out = shiftdim(in,N) ndims = length(size(in)); out = permute(in,[N:ndims,1:N-1]); However, the Matlab function shiftdim also takes a negative argument, and adds singleton dimensions (sort of the opposite of the "squeeze" function). For example if A is a 1xN vector, shiftdim(A,-1) is a 1x1xN array. I think that part could be handled using reshape, but it's not obvious to me exactly how. Quentin ------------------------------------------------------------- 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 -------------------------------------------------------------