Keep part of a vector or a matrix.
Syntax
Y = wkeep(X,L,O)
Y = wkeep(X,L)
Description
wkeep is a general utility.
For a vector, Y = wkeep(X,L,O) extracts the vector Y from the vector X. L is the length of result Y. If O = 'c' ('l' , 'r' respectively), Y is the central (left, right respectively) part of X.
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. S is the size of Y.
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
[ Previous | Help Desk | Next ]