tags:

views:

33

answers:

2

I am trying the following right now:

function isNum = isItANum(string)  
    isNum = isempty(str2num(string))  
end

The problem is if I have a date '1998/34/2', I want my function to say no.

A: 

do a loop so that you split the string in single characters, and if any char fail, then return 0.

Mascarpone
+1  A: 

From help str2num:

 *Caution:* As `str2num' uses the `eval' function to do the
 conversion, `str2num' will execute any code contained in the
 string S.  Use `str2double' instead if you want to avoid the use
 of `eval'.

 See also: str2double, eval

Looks like you can replace your function with ~isnan(str2double(string))

mtrw