time | Calls | line |
---|
| | 1 | function y = flip(x,dim)
|
| | 2 | %FLIP Flip the order of elements
|
| | 3 | % Y = FLIP(X) returns a vector Y with the same dimensions as X, but with the
|
| | 4 | % order of elements flipped. If X is a matrix, each column is flipped
|
| | 5 | % vertically. For N-D arrays, FLIP(X) operates on the first
|
| | 6 | % nonsingleton dimension.
|
| | 7 | %
|
| | 8 | % FLIP(X,DIM) works along the dimension DIM.
|
| | 9 | %
|
| | 10 | % For example, FLIP(X) where
|
| | 11 | %
|
| | 12 | % X = 1 4 produces 3 6
|
| | 13 | % 2 5 2 5
|
| | 14 | % 3 6 1 4
|
| | 15 | %
|
| | 16 | %
|
| | 17 | % Class support for input X:
|
| | 18 | % float: double, single
|
| | 19 | % integers: uint8, int8, uint16, int16, uint32, int32, uint64, int64
|
| | 20 | % char, logical
|
| | 21 | %
|
| | 22 | % See also FLIPLR, FLIPUD, ROT90, PERMUTE.
|
| | 23 |
|
| | 24 | % Copyright 1984-2018 The MathWorks, Inc.
|
| | 25 |
|
| | 26 | % Argument parsing
|
< 0.001 | 182 | 27 | if nargin == 1
|
| | 28 | dim = find(size(x)~=1,1,'first'); % Find leading singleton dimensions
|
| | 29 | if isempty(dim) % scalar case
|
| | 30 | dim = 2;
|
| | 31 | end
|
< 0.001 | 182 | 32 | else
|
0.002 | 182 | 33 | dim = matlab.internal.math.getdimarg(dim);
|
< 0.001 | 182 | 34 | end
|
| | 35 |
|
< 0.001 | 182 | 36 | dimsize = size(x,dim);
|
< 0.001 | 182 | 37 | if dimsize <= 1 && (isreal(x) || ~isnumeric(x))
|
| | 38 | % No-op.
|
< 0.001 | 8 | 39 | y = x;
|
< 0.001 | 174 | 40 | else
|
| | 41 | % Create the index that will transform x.
|
0.003 | 174 | 42 | v(1:max(dim,ndims(x))) = {':'};
|
| | 43 | % Flip dimension dim.
|
0.002 | 174 | 44 | v{dim} = dimsize:-1:1;
|
| | 45 | % Index with v.
|
0.005 | 174 | 46 | y = x(v{:});
|
< 0.001 | 182 | 47 | end
|
Other subfunctions in this file are not included in this listing.