Documentation Center

  • Trial Software
  • Product Updates

wkeep

Keep part of vector or matrix

Syntax

Y = wkeep(X,L,OPT)
Y = wkeep(X,L,FIRST)
Y = wkeep(X,L)
Y = wkeep(X,L,'c')
Y = wkeep(X,S,[FIRSTR FIRSTC])

Description

wkeep is a general utility.

For a vector, Y = wkeep(X,L,OPT) extracts the vector Y from the vector X. The length of Y is L.

If OPT = 'c' ('l', 'r', respectively), Y is the central (left, right, respectively) part of X.

Y = wkeep(X,L,FIRST) returns the vector X(FIRST:FIRST+L-1).

Y = wkeep(X,L) is equivalent to Y = wkeep(X,L,'c').

For a matrix, Y = wkeep(X,S) extracts the central part of the matrix X. The size of Y is S.

Y = wkeep(X,S,[FIRSTR FIRSTC]) extracts the submatrix of matrix X, of size S and starting from X(FIRSTR,FIRSTC).

Examples

% For a vector. 
x = 1:10;
y = wkeep(x,6,'c')
y =
    3     4     5     6     7     8

y = wkeep(x,6)
y =
    3     4     5     6     7     8

y = wkeep(x,7,'c')
y =
    2     3     4     5     6     7     8
y = wkeep(x,6,'l')
y =
    1     2     3     4     5     6

y = wkeep(x,6,'r')
y =
    5     6     7     8     9     10

% For a matrix. 
x = magic(5)
x =
    17     24      1      8     15 
    23      5      7     14     16 
     4      6     13     20     22 
    10     12     19     21      3 
    11     18     25      2      9

y = wkeep(x,[3 2])
y =
    5     7
    6    13
   12    19
Was this topic helpful?