extract numeric values from strings in xls files?

2 次查看(过去 30 天)
Hi,
I have an xls file with 10 columns. The columns are full of string and inside the strings there are some numeric values that I need to extract and put in a new column. I was thinking to do something like this:
load doc.txt %to load the file in txt format
for i=1:total lines of txt
read each line
take numeric values
put in table
end
I don't even know if any from above is possible in matlab. Is it possible to read strings and from them extract the numeric values?

回答(1 个)

Walter Roberson
Walter Roberson 2011-11-19
You can use regexp() and str2double()
Note: if the values are floating point numbers that might be in exponential format, then it is fairly difficult to construct a correct regexp pattern that will match such numbers properly. When working with such numbers, it is much easier if there is a delimiter such as space or comma.

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by