Home > atmlab > handy > tail.m

tail

PURPOSE ^

TAIL End part of a vector.

SYNOPSIS ^

function t = tail( x, l )

DESCRIPTION ^

 TAIL   End part of a vector.

    Returns the tail of any variable that can be indexed as (1:n).
   
    The function will return a result if given a non-vector input (for
    example, a matrix). No check of the type of the input is performed
    for efficiency reasons.

    The last element of a vector is obtained by
       tail( x, 1 );

    To ask for a tail with a length exceeding the vector lengths results in
    an error.

 FORMAT   t = tail( x, l )
        
 OUT   t   Tail fo the vector.
 IN    x   The full vector.
       l   Length of tail to extract.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

tail.m

SOURCE CODE ^

0001 % TAIL   End part of a vector.
0002 %
0003 %    Returns the tail of any variable that can be indexed as (1:n).
0004 %
0005 %    The function will return a result if given a non-vector input (for
0006 %    example, a matrix). No check of the type of the input is performed
0007 %    for efficiency reasons.
0008 %
0009 %    The last element of a vector is obtained by
0010 %       tail( x, 1 );
0011 %
0012 %    To ask for a tail with a length exceeding the vector lengths results in
0013 %    an error.
0014 %
0015 % FORMAT   t = tail( x, l )
0016 %
0017 % OUT   t   Tail fo the vector.
0018 % IN    x   The full vector.
0019 %       l   Length of tail to extract.
0020 
0021 % 2002-12-16   Created by Patrick Eriksson.
0022 
0023 
0024 function t = tail( x, l )
0025 
0026 if l > length(x)
0027   serr = sprintf( ['You have asked for a tail of length %d, but *x* has ',...
0028                                           'only %d elements.'], l, length(x) );
0029   error( serr );
0030 end
0031 
0032 
0033 t = x( length(x) + ((-l+1):0) );

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005