shiftr

Purpose

Shifts the rows of a matrix.

Format

y = shiftr(x, s, f)
Parameters:
  • x (NxK matrix) – data to be shifted
  • s (scalar or Nx1 vector) – specifies the amount of shift
  • f (scalar or Nx1 vector) – specifies the value to fill in
Returns:

y (NxK matrix) – shifted matrix

Examples

// Data matrix
x = { 1 2,
      3 4 };

// Amount of shift
s = { 1,
     -1 };

// Value to fill in
f = { 99,
     999 };

// Shift the matrix
y = shiftr(x, s, f);

Now y is equal to:

99   1
4  999
// Data
x = { 1 2 3,
      4 5 6,
      7 8 9 };

// Amount to shift
s = { 0,
      1,
      2 };

// Value to fill in
f = 0;

// Shift the matrix
y2 = shiftr(x, s, f);

Now y2 is equal to:

1  2  3
0  4  5
0  0  7

Remarks

The shift is performed within each row of the matrix, horizontally. If the shift value is positive, the elements in the row will be moved to the right. A negative shift value causes the elements to be moved to the left. The elements that are pushed off the end of the row are lost, and the fill value will be used for the new elements on the other end.

See also

Functions rotater()