Code covered by the BSD License

### Highlights from Find numerical values (digits) in a string array.

Be the first to rate this file! 7 Downloads (last 30 days) File Size: 2.3 KB File ID: #28231

# Find numerical values (digits) in a string array.

by

Function that determines for a given string 'str' if some of its characters are digits from 0 to 9.

File Information
Description

flags = isstrdigit( str, M, N )

Function that determines for a given string 'str' if some of its characters represent digits from 0 to 9.

If 'M' and 'N' are not specified, all positions are tested by default.
The output 'flags' will be the size of input 'str', with each position set as 0 where no digit was found or 1 otherwise.

If 'M' is specified and 'N' is not, the only position tested in the string is given by the position in 'M'.
The output 'flags' will be returned as '0' if no digit is found, or '1' otherwise.

If both 'M' and 'N' are specified, positions from 'M' to 'N' are tested.
The output 'flags' will be the size of input 'str', with each position set as '0' where no digit was found or '1' otherwise.
Any untested position will be set as 'NaN'.

If 'str' is a multidimensional array, for each row all columns are counted until 'M' and 'N' are found.

NOTE:
The Matlab built-in function 'isstrprop' can be used to do this, but works a different way.

MATLAB release MATLAB 7.10 (R2010a)
20 Jul 2010

No H1 line.
One very important remark: Matlab is set to work rowwise by default which means that when talking about positions it counts vertically and not horizontally as your functions does.
An example:
Out = rand(2)
0.9572 0.8003
0.4854 0.1419
Out(2) = 0.4854 % and not 0.8003

Another point, your function doesn't work on 3D char arrays:
In(:,:,1) = ['is012digit?'; 'is345digit?'];
In(:,:,2) = ['issf234git?'; 'is2dig34it?'];

You can equivalently use ismember (on nD arrays as well):
% double('0123456789') --> 48:57
ismember(In, 48:57);

~isempty(find(digits == str(k))) can be replaced by
any(digits == str(k)) % faster

Oleg