samer@4: function B=revdims(A,N) samer@4: % revdims - reverse N dimensions of a multidimensional array samer@4: % samer@4: % revdims :: [[D:[[1,M]]]], N:natural -> [[D2:[[1,M]]]]. samer@4: % revdims :: [[D:[[1,M]]]] -> [[D2:[[1,M]]]]. samer@4: % samer@4: % This takes an array of size [D(1:N) DX] samer@4: % and returns an array of size [D(N:-1:1) DX] samer@4: % where DX are the rest of the dimensions after the Nth and are samer@4: % unaffected. N defaults to the number of dimensions disregarding samer@4: % trailing singletons, ie numdims(A)==length(size1(A)) samer@4: samer@4: if nargin<2, N=numdims(A); end samer@4: samer@4: ND=max(N,2); samer@4: DD=1:ND; samer@4: DD(1:N)=fliplr(DD(1:N)); samer@4: B=permute(A,DD);