string to num

18 views (last 30 days)
Charles
Charles on 7 Dec 2011
Hi,
I am reading string data of this format from a text file:
(20:200,40:300)
This is the area of an image which I wish to select. How do I convert this string to number range. Thanks.
Charles-

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 7 Dec 2011
Hi Charles,
a simple way would be replace all non digits by spaces and use str2num afterwards:
x = '(20:200,40:300)';
x(~isstrprop(x, 'digit')) = ' ';
xNumber = str2num(x)
Titus
  12 Comments
Andrei Bobrov
Andrei Bobrov on 7 Dec 2011
str2double(regexp(x,'\d+','match'))

Sign in to comment.

More Answers (1)

osman
osman on 7 Dec 2011
use str2num
  2 Comments
Charles
Charles on 7 Dec 2011
As Sean de Wolski pointed out, it doesn't work.

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!