string to num

2 次查看(过去 30 天)
Charles
Charles 2011-12-7
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-

采纳的回答

Titus Edelhofer
Titus Edelhofer 2011-12-7
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 个评论
Charles
Charles 2011-12-7
:-) I truly appreciate your assistance. Really, thanks a lot.
Andrei Bobrov
Andrei Bobrov 2011-12-7
str2double(regexp(x,'\d+','match'))

请先登录,再进行评论。

更多回答(1 个)

osman
osman 2011-12-7
use str2num
  2 个评论
Sean de Wolski
Sean de Wolski 2011-12-7
That won't work. He'd going to need to parse the string based on '(,:' first
Charles
Charles 2011-12-7
As Sean de Wolski pointed out, it doesn't work.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by