Home > m > helper > ltpda_str2cells.m

ltpda_str2cells

PURPOSE ^

LTPDA_STR2CELLS Take a single string and separate out individual "elements" into a new cell array.

SYNOPSIS ^

function newCell = ltpda_str2cells(someString)

DESCRIPTION ^

 LTPDA_STR2CELLS Take a single string and separate out individual "elements" into a new cell array.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: LTPDA_STR2CELLS Take a single string and separate out individual
              "elements" into a new cell array. Elements are defined as non-blank characters separated by
              spaces.

              Similar to str2cell, except str2cell requires an array of strings.
              str2cells requires only 1 string.

 CALL:       newCell = ltpda_str2cells(aString)

 INPUTS:     aString - string

 OUTPUTS:    newCell - cell array of strings

 EXAMPLE:    Consider the following string in the workspace:

 aString = ' a  b        c  d  efgh ij      klmnopqrs t u v w xyz    '
 newCell = 'a'
           'b'
           'c'
           'd'
           'efgh'
           'ij'
           'klmnopqrs'
           't'
           'u'
           'v'
           'w'
           'xyz'

 REMARK:  This is copied from a file found on MathWorks File Exchange.

 VERSION: $Id: ltpda_str2cells.html,v 1.14 2008/03/31 10:27:31 hewitson Exp $

 HISTORY: 26-01-2007 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newCell = ltpda_str2cells(someString)
0002 % LTPDA_STR2CELLS Take a single string and separate out individual "elements" into a new cell array.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: LTPDA_STR2CELLS Take a single string and separate out individual
0007 %              "elements" into a new cell array. Elements are defined as non-blank characters separated by
0008 %              spaces.
0009 %
0010 %              Similar to str2cell, except str2cell requires an array of strings.
0011 %              str2cells requires only 1 string.
0012 %
0013 % CALL:       newCell = ltpda_str2cells(aString)
0014 %
0015 % INPUTS:     aString - string
0016 %
0017 % OUTPUTS:    newCell - cell array of strings
0018 %
0019 % EXAMPLE:    Consider the following string in the workspace:
0020 %
0021 % aString = ' a  b        c  d  efgh ij      klmnopqrs t u v w xyz    '
0022 % newCell = 'a'
0023 %           'b'
0024 %           'c'
0025 %           'd'
0026 %           'efgh'
0027 %           'ij'
0028 %           'klmnopqrs'
0029 %           't'
0030 %           'u'
0031 %           'v'
0032 %           'w'
0033 %           'xyz'
0034 %
0035 % REMARK:  This is copied from a file found on MathWorks File Exchange.
0036 %
0037 % VERSION: $Id: ltpda_str2cells.html,v 1.14 2008/03/31 10:27:31 hewitson Exp $
0038 %
0039 % HISTORY: 26-01-2007 M Hewitson
0040 %             Creation
0041 %
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 % If someString is empty then return an empty Cell
0045 if isempty(someString)
0046   newCell = {};
0047   return
0048 end
0049 
0050 % Trim off any leading & trailing blanks
0051 someString=strtrim(someString);
0052 
0053 % Locate all the white-spaces
0054 spaces=isspace(someString);
0055 
0056 % Build the cell array
0057 idx=0;
0058 while sum(spaces)~=0
0059     idx=idx+1;
0060     newCell{idx}=strtrim(someString(1:find(spaces==1,1,'first')));
0061     someString=strtrim(someString(find(spaces==1,1,'first')+1:end));
0062     spaces=isspace(someString);
0063 end
0064 newCell{idx+1}=someString;
0065

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003