view general/arrutils/revdims.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents e44f49929e56
children
line wrap: on
line source
function B=revdims(A,N)
% revdims - reverse N dimensions of a multidimensional array
%
% revdims :: [[D:[[1,M]]]], N:natural -> [[D2:[[1,M]]]].
% revdims :: [[D:[[1,M]]]] -> [[D2:[[1,M]]]].
%
% This takes an array of size [D(1:N) DX]
% and returns an array of size [D(N:-1:1) DX]
% where DX are the rest of the dimensions after the Nth and are
% unaffected. N defaults to the number of dimensions disregarding
% trailing singletons, ie numdims(A)==length(size1(A))

if nargin<2, N=numdims(A); end

ND=max(N,2);
DD=1:ND;
DD(1:N)=fliplr(DD(1:N));
B=permute(A,DD);