Conveter a string with space in a number
3 次查看(过去 30 天)
显示 更早的评论
A have one vector returned by the function textscan which have spaces inside the numerical string.
E.g.:
' 0 0 , 2 3 '
' 1 2 , 1 5 '
First, a have to substitute the ',' by '.' (it's simple) but how I remove the spaces? Because using str2num in this vector is returned error.
2 个评论
Stephen23
2020-8-26
编辑:Stephen23
2020-8-26
"A have one vector returned by the function textscan which have spaces inside the numerical string."
I am surprised that no one brought up the obvious solution, to fix the (likely) problem at its source by handling the file encoding properly. Then textscan would import the data correctly.
Image Analyst
2020-8-26
Well, someone might have, but the original poster forgot to attach the original text file. That is a common omission. For some reason, many/most posters totally ignore the posting guidelines that they are shown when they post the question, one of which says to attach their data.
采纳的回答
Image Analyst
2015-6-20
It's pretty much the same except that you set it equal to [] instead of a decimal point:
str(str == ' ') = []; % Remove spaces
3 个评论
Walter Roberson
2015-6-20
cellfun(@(str)str(2:2:end), dataArray, 'Uniform', 0)
in the case where the odd-numbered characters are the blanks.
更多回答(1 个)
Azzi Abdelmalek
2015-6-20
编辑:Azzi Abdelmalek
2015-6-20
s={' 0 0 , 2 3 ';'1 2 , 1 5 '}
a=strrep(s,',','.')
b=strrep(a,' ','')
out=str2double(b)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!