0

私は今、次のことを試しています:

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

問題は、日付が '1998/34/2' の場合、自分の関数にノーと言わせたいということです。

4

2 に答える 2

1

から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

関数を次のように置き換えることができるようです~isnan(str2double(string))

于 2010-02-15T03:24:59.900 に答える
0

文字列を単一の文字に分割するようにループを実行し、文字が失敗した場合は 0 を返します。

于 2010-02-14T12:20:25.627 に答える