Tuesday, May 12, 2009

Matching an empty string in a cellstring array in Matlab

Say you have the following cellstring array in Matlab :
a =
{'0.13'
'0.48'
'0.11'
'0.1'
''
''
'0.03'
'0.22'
'0.09'
'0.29'
'0.14'
'0.33'}

In order to match the cellstring array rows with empty strings, use :

regexp(a, '^\d')
or
cellfun('isempty', regexp(a, '^\d'))

Here we are taking advantage of the fact that we have all numeric strings. Anybody any idea on how to accomplish this if the non-empty strings were composed of letters?

No comments:

Post a Comment