FreeMat
FLIPDIM Reverse a Matrix Along a Given Dimension

Section: Array Generation and Manipulations

USAGE

Reverses an array along the given dimension. The syntax for its use is

   y = flipdim(x,n)

where x is matrix, and n is the dimension to reverse.

Example

The following examples show some uses of flipdim on N-dimensional arrays.

--> x = int32(rand(4,5,3)*10)

x = 

(:,:,1) = 
  5  2  4  2  8 
  7  6  6  6  7 
  7  0  1  1  0 
  3  2  1  9  9 

(:,:,2) = 
 10  6  3  3  1 
  1  2  5  7 10 
  9  7  5  1  4 
  3 10  4  4  3 

(:,:,3) = 
  3  6  5  8  9 
  9  8  5  3  0 
  1  7  9  4  8 
  4  6  4  9  5 

--> flipdim(x,1)

ans = 

(:,:,1) = 
  3  2  1  9  9 
  7  0  1  1  0 
  7  6  6  6  7 
  5  2  4  2  8 

(:,:,2) = 
  3 10  4  4  3 
  9  7  5  1  4 
  1  2  5  7 10 
 10  6  3  3  1 

(:,:,3) = 
  4  6  4  9  5 
  1  7  9  4  8 
  9  8  5  3  0 
  3  6  5  8  9 

--> flipdim(x,2)

ans = 

(:,:,1) = 
  8  2  4  2  5 
  7  6  6  6  7 
  0  1  1  0  7 
  9  9  1  2  3 

(:,:,2) = 
  1  3  3  6 10 
 10  7  5  2  1 
  4  1  5  7  9 
  3  4  4 10  3 

(:,:,3) = 
  9  8  5  6  3 
  0  3  5  8  9 
  8  4  9  7  1 
  5  9  4  6  4 

--> flipdim(x,3)

ans = 

(:,:,1) = 
  3  6  5  8  9 
  9  8  5  3  0 
  1  7  9  4  8 
  4  6  4  9  5 

(:,:,2) = 
 10  6  3  3  1 
  1  2  5  7 10 
  9  7  5  1  4 
  3 10  4  4  3 

(:,:,3) = 
  5  2  4  2  8 
  7  6  6  6  7 
  7  0  1  1  0 
  3  2  1  9  9