| Prev | Next | shift |
| Syntax |
y = shift(x, Nshift) |
| Include: |
include spt\shift.oms |
| See Also | revolve |
ARGUMENTS:
INPUTS:
x = MATRIX, any numerical type.
Nshift = SCALAR, any numerical type, coerced to INTEGER
before processing. Represents the number of row
positions matrix is to be shifted.
RETURN: MATRIX, column-wise shifted version of input. Type
same as input.
Shift the rows of input matrix by amount 'Nshift'
in a 'fall-off-the-end' fashion. Similar to a bi-directional
shift register that fills in vacated locations with zeros.
For matrix inputs, each row of the matrix 'x' is shifted to
higher row index for positive 'Nshift', or shifted to lower
row index for negative 'Nshift'. Vacated positions at the
ends of the matrix are filled with zeros. For scalar inputs
or Nshift=0, function returns the input unchanged.
For the special case of a row vector being input, the
function treats the vector as a column vector and shifts it
accordingly, returning a row vector.
'Nshift' is internally coerced to its' integer part before revolution. Returned matrix is same type as input matrix.
For Scalar Input:
O>shift(-12)
-12
For Row Vectors:
O>x = [1,2,3,4,5]
O>x
[ 1 , 2 , 3 , 4 , 5 ]
O>shift(x,2)
[ 0 , 0 , 1 , 2 , 3 ]
For Column Vectors:
O>x = {1,2,3,4,5}
O>x
{
1
2
3
4
5
}
O>shift(x,-2)
{
3
4
5
0
0
}
For Matrices:
O>x = seq(5)*seq(5)'
O>x
{
[ 1 , 2 , 3 , 4 , 5 ]
[ 2 , 4 , 6 , 8 , 10 ]
[ 3 , 6 , 9 , 12 , 15 ]
[ 4 , 8 , 12 , 16 , 20 ]
[ 5 , 10 , 15 , 20 , 25 ]
}
O>shift(x,-3)
{
[ 4 , 8 , 12 , 16 , 20 ]
[ 5 , 10 , 15 , 20 , 25 ]
[ 0 , 0 , 0 , 0 , 0 ]
[ 0 , 0 , 0 , 0 , 0 ]
[ 0 , 0 , 0 , 0 , 0 ]
}