function y = flipdim(x,dim)
%FLIPDIM Flip matrix along specified dimension.
%   FLIPDIM(X,DIM) returns X with dimension DIM flipped.  
%   For example, FLIPDIM(X,1) where
%   
%       X = 1 4  produces  3 6
%           2 5            2 5
%           3 6            1 4
%
%   See also FLIPLR, FLIPUD, ROT90, PERMUTE.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.11 $  $Date: 1997/11/21 23:28:48 $

if nargin~=2, error('Requires two arguments.'); end
if dim<=0, error('DIM must be a positive integer.'); end
dim = floor(dim);
siz = [size(x) ones(1,max(dim-ndims(x),0))];
v = cell(size(siz));
for i=1:length(siz),
  v(i) = {':'};
end
v(dim) = {siz(dim):-1:1}; % Flip dimension v
y = x(v{:}); % "Index with v" and flip dimension v.

