Home > m > helper > ltpda_str2cells.m

ltpda_str2cells

PURPOSE ^

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

SYNOPSIS ^

function newCell = ltpda_str2cells(someString)

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.

 Example: Consider the following string in the workspace:
 aString = ' a  b        c  d  efgh ij      klmnopqrs t u v w xyz    '
 
 >> newCell=ltpda_str2cells(aString)'
 
 newCell = 
 
     'a'
     'b'
     'c'
     'd'
     'efgh'
     'ij'
     'klmnopqrs'
     't'
     'u'
     'v'
     'w'
     'xyz'

 M Hewitson 26-01-07

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

 $Id: ltpda_str2cells.html,v 1.1 2007/06/08 14:15:10 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newCell = ltpda_str2cells(someString)
0002 
0003 % LTPDA_STR2CELLS Take a single string and separate out individual "elements" into a new
0004 % cell array.  Elements are defined as non-blank characters separated by
0005 % spaces.
0006 %
0007 % Similar to str2cell, except str2cell requires an array of strings.
0008 % str2cells requires only 1 string.
0009 %
0010 % Example: Consider the following string in the workspace:
0011 % aString = ' a  b        c  d  efgh ij      klmnopqrs t u v w xyz    '
0012 %
0013 % >> newCell=ltpda_str2cells(aString)'
0014 %
0015 % newCell =
0016 %
0017 %     'a'
0018 %     'b'
0019 %     'c'
0020 %     'd'
0021 %     'efgh'
0022 %     'ij'
0023 %     'klmnopqrs'
0024 %     't'
0025 %     'u'
0026 %     'v'
0027 %     'w'
0028 %     'xyz'
0029 %
0030 % M Hewitson 26-01-07
0031 %
0032 % ** This is copied from a file found on MathWorks File Exchange.
0033 %
0034 % $Id: ltpda_str2cells.html,v 1.1 2007/06/08 14:15:10 hewitson Exp $
0035 %
0036 
0037 % Trim off any leading & trailing blanks
0038 someString=strtrim(someString);
0039 
0040 % Locate all the white-spaces
0041 spaces=isspace(someString);
0042 
0043 % Build the cell array
0044 idx=0;
0045 while sum(spaces)~=0
0046     idx=idx+1;
0047     newCell{idx}=strtrim(someString(1:find(spaces==1,1,'first')));
0048     someString=strtrim(someString(find(spaces==1,1,'first')+1:end));
0049     spaces=isspace(someString);
0050 end
0051 newCell{idx+1}=someString;

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003