Domanda
Sto cercando la seguente ora:
function isNum = isItANum(string)
isNum = isempty(str2num(string))
end
Il problema è se ho un appuntamento '1998/34/2', voglio che la mia funzione di dire di no.
Soluzione
Da 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
Sembra che si può sostituire la funzione con ~isnan(str2double(string))
Altri suggerimenti
fare un ciclo in modo da dividere la stringa in caratteri singoli, e se qualche carattere non riescono, per poi tornare 0.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow