Adding space/symbol to the readed line.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Cedric
2013-1-11
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)?
采纳的回答
Cedric
2013-1-11
编辑:Cedric
2013-1-11
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!