Adding space/symbol to the readed line.

Hi.
I had readed line of numbers as a char, like this: 2.450333.000 2.450333.000 5.100 1.230 1.210333.000 333.000 7.87
I would like to add spaces between the numbers to separate them. Fuction can add a space before all occuring numbers. It isn't importent how many space will be before the number, but that every number must be separately.
I was using B = regexprep(A, '333(\w*).000', ' 333.000 ') but when puted together numbers will change what can happen someday, it won't work. Can You suggest me another, better idea?
Thank You.

4 comentarios

Walter Roberson
Walter Roberson el 11 de En. de 2013
In a previous question http://www.mathworks.co.uk/matlabcentral/answers/58333-loading-data-from-document-and-isolating-numbers you said that the number that needs to be split at is always 99 . Now it is 333, and might change. If you want the general solution to this you need to indicate how to recognize the break between numbers. For example, is it the case that the previous numbers will always have three digits after the decimal place? (If so then 7.87 fails that pattern.)
ZK
ZK el 11 de En. de 2013
Editada: ZK el 11 de En. de 2013
Yes exactly pattern has changed in this data, but I will handle this in the future. I am thinking about solution like (*.***) adding space (*-any digit).
Sorry my mistake it is 7.870.
Cedric
Cedric el 11 de En. de 2013
In the line that you give at the top of your question, you already inserted spaces actually (?) Do you want to match a pattern (here '333' + whatever + '000') and insert one space directly after each match, or is it simpler than pattern matching (e.g. because the format is more regular that what you get with '\w*')? In your example, where did spaces in ' 5.100 1.230 ' come from? Are they already there or do you have to add them as well (I'm asking as they don't match your pattern)?
ZK
ZK el 11 de En. de 2013
Spaces between ' 5.100 1.230 ' were there. Yes I would like to give a space before and after all numbers so it would look like this:
2.450 333.000 2.450 333.000 5.100 1.230 1.210 333.000 333.000 7.870

Iniciar sesión para comentar.

 Respuesta aceptada

Cedric
Cedric el 11 de En. de 2013
Editada: Cedric el 11 de En. de 2013
Assuming that your number format is characterized by always having 3 digits after the decimal dot, you can use the following instead of matching numbers that can vary (e.g. 3's):
s = '2.450333.0002.450333.0005.1001.2301.210333.000333.0007.870' ;
regexp( s, '\d*.\d{3}', 'match' )
Note that the {3} means 3 occurrences of the previous \d and is not related to the 3's in the string.
Cedric

1 comentario

ZK
ZK el 11 de En. de 2013
Yes I had noticed. Thank You, with small changes I will be using it to many patterns. Greetings.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

ZK
el 11 de En. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by