string to num

2 visualizaciones (últimos 30 días)
Charles
Charles el 7 de Dic. de 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-

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by