MATLAB Answers

Info

This question is closed.

Zaza
0

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)...

Asked by Zaza
on 23 Nov 2012
for example:
st = '23487';
r = 1;
(also '00023487' is acceptable or any number of leading zeros).
but
st = '-4e';
r = 0;

  1 Comment

I am closing this question. Please edit it to include what you have tried so far.

Tags

Products

2 Answers

Answer by Arthur
on 23 Nov 2012

r = ~isnan(str2double(st));

  0 Comments


Answer by Azzi Abdelmalek
on 23 Nov 2012

a='1.3125';
r=numel(regexp(a,'[0-9.]'))==numel(a)

  0 Comments