Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slcompresstext
Home > sltoolbox > text > slcompresstext.m

slcompresstext

PURPOSE ^

SLCOMPRESSTEXT Compresses a cell array of text

SYNOPSIS ^

function Tc = slcompresstext(T, varargin)

DESCRIPTION ^

SLCOMPRESSTEXT Compresses a cell array of text

 $ Syntax $
   - Tc = slcompresstext(T, ...)

 $ Arguments $
   - T:        the source text to be compressed
   - Tc:       the compressed text

 $ Description $
   - Tc = slcompresstext(T, ...) compresses the text T, represented in
     cell array of lines. You can specify the properties to control the
     process of compression.
     \*
     \t    Table 1. Properties of Text Compression
     \h    name        &    description
          'rmempty'    &  whether to remove empty line (default = true)
          'proc'       &  the method of processing each line
                          (default='trim')
                          - 'off': do not process
                          - 'trim': trim the leading and trailing spaces
                          - 'deblank': trim only the trailing spaces

 $ History $
   - Created by Dahua Lin, on Aug 9th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
  • edl_readenvvars EDL_READENVVARS Reads in a file with environment variables

SOURCE CODE ^

0001 function Tc = slcompresstext(T, varargin)
0002 %SLCOMPRESSTEXT Compresses a cell array of text
0003 %
0004 % $ Syntax $
0005 %   - Tc = slcompresstext(T, ...)
0006 %
0007 % $ Arguments $
0008 %   - T:        the source text to be compressed
0009 %   - Tc:       the compressed text
0010 %
0011 % $ Description $
0012 %   - Tc = slcompresstext(T, ...) compresses the text T, represented in
0013 %     cell array of lines. You can specify the properties to control the
0014 %     process of compression.
0015 %     \*
0016 %     \t    Table 1. Properties of Text Compression
0017 %     \h    name        &    description
0018 %          'rmempty'    &  whether to remove empty line (default = true)
0019 %          'proc'       &  the method of processing each line
0020 %                          (default='trim')
0021 %                          - 'off': do not process
0022 %                          - 'trim': trim the leading and trailing spaces
0023 %                          - 'deblank': trim only the trailing spaces
0024 %
0025 % $ History $
0026 %   - Created by Dahua Lin, on Aug 9th, 2006
0027 %
0028 
0029 %% parse and verify input arguments
0030 
0031 if ~iscell(T)
0032     error('sltoolbox:invalidarg', ...
0033         'T should be a cell array of strings');
0034 end
0035 
0036 opts.rmempty = true;
0037 opts.proc = 'trim';
0038 opts = slparseprops(opts, varargin{:});
0039 
0040 switch opts.proc
0041     case 'off'
0042         procfunc = [];
0043     case 'trim'
0044         procfunc = 'strtrim';
0045     case 'deblank'
0046         procfunc = 'deblank';
0047     otherwise
0048         error('sltoolbox:invalidarg', ...
0049             'Invalid string processing method %s', opts.proc);
0050 end
0051 
0052 %% Process
0053 
0054 if ~isempty(procfunc)
0055     Tc = slfiltertext(T, procfunc);
0056 else
0057     Tc = T;
0058 end
0059 
0060 %% Select
0061 
0062 if opts.rmempty
0063     nlines = length(Tc);
0064     is_effline = true(nlines, 1);
0065     has_deleted = false;
0066     for i = 1 : nlines
0067         if isempty(Tc{i})
0068             is_effline(i) = false;
0069             has_deleted = true;
0070         end        
0071     end
0072     
0073     if has_deleted
0074         Tc = Tc(is_effline);
0075     end
0076 end
0077 
0078 
0079 
0080 
0081

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com