Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how can i convert a string to a number (without using the str2num function) so if the string represents a number the value is 1? (otherwise the value is 0)...

1 visualización (últimos 30 días)
for example:
st = '23487';
r = 1;
(also '00023487' is acceptable or any number of leading zeros).
but
st = '-4e';
r = 0;

Respuestas (2)

Arthur
Arthur el 23 de Nov. de 2012
r = ~isnan(str2double(st));

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Nov. de 2012
a='1.3125';
r=numel(regexp(a,'[0-9.]'))==numel(a)

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by