Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@prog/str2cells.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function newCell = str2cells(someString) | |
2 % STR2CELLS Take a single string and separate out individual "elements" into a new cell array. | |
3 % | |
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5 % | |
6 % DESCRIPTION: STR2CELLS Take a single string and separate out individual | |
7 % "elements" into a new cell array. Elements are defined as non-blank characters separated by | |
8 % spaces. | |
9 % | |
10 % Similar to str2cell, except str2cell requires an array of strings. | |
11 % str2cells requires only 1 string. | |
12 % | |
13 % CALL: newCell = str2cells(aString) | |
14 % | |
15 % INPUTS: aString - string | |
16 % | |
17 % OUTPUTS: newCell - cell array of strings | |
18 % | |
19 % EXAMPLE: Consider the following string in the workspace: | |
20 % | |
21 % aString = ' a b c d efgh ij klmnopqrs t u v w xyz ' | |
22 % newCell = 'a' | |
23 % 'b' | |
24 % 'c' | |
25 % 'd' | |
26 % 'efgh' | |
27 % 'ij' | |
28 % 'klmnopqrs' | |
29 % 't' | |
30 % 'u' | |
31 % 'v' | |
32 % 'w' | |
33 % 'xyz' | |
34 % | |
35 % REMARK: This is copied from a file found on MathWorks File Exchange. | |
36 % | |
37 % VERSION: $Id: str2cells.m,v 1.1 2008/06/18 13:35:11 hewitson Exp $ | |
38 % | |
39 % HISTORY: 26-01-2007 M Hewitson | |
40 % Creation | |
41 % | |
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
43 | |
44 % If someString is empty then return an empty Cell | |
45 if isempty(someString) | |
46 newCell = {}; | |
47 return | |
48 end | |
49 | |
50 % Trim off any leading & trailing blanks | |
51 someString=strtrim(someString); | |
52 | |
53 % Locate all the white-spaces | |
54 spaces=isspace(someString); | |
55 | |
56 % Build the cell array | |
57 idx=0; | |
58 while sum(spaces)~=0 | |
59 idx=idx+1; | |
60 newCell{idx}=strtrim(someString(1:find(spaces==1,1,'first'))); | |
61 someString=strtrim(someString(find(spaces==1,1,'first')+1:end)); | |
62 spaces=isspace(someString); | |
63 end | |
64 newCell{idx+1}=someString; | |
65 |