xlsread won't read decimal numbers

7 views (last 30 days)
I'm sorry if this question has already been asked, but I couldn't find a solution to my specific problem. I'm using Matlab 2014b. I'm trying to import some decimal numbers from an xlsx-excel sheet. Although my computer environment is german, the decimal numbers in the sheet do use a decimal point instead of a comma, i.e. they have the form 2.7268. However, when using [num, text, raw]=xlsread(filename, sheet, xlRange] and specifying the column I want to read, the decimal numbers are always returned as strings (text, respectively) and the num-Array is empty. The same thing happens when using the manual "Import Data" command with column vectors (and then using cell2mat on them). "Numeric matrix" replaces all values with NaN. This poses a problem as I have to use these velocity-values in a plot. Can anybody help me out? I have no idea what I'm doing wrong. Edit: My excel-sheet looks something like this:
No. #Event Time #Velocity [km/s]
1 #20140805 13:22:59.671# 2.657101# 2.657101
2 #20140805 13:23:00.483# 0.556091# 0.556091
3 #20140805 13:23:00.803# 0.590656# 0.590656
4 #20140805 13:23:03.679# 1.142748# 1.142748
5 #20140805 13:23:05.292# 1.393049# 1.393049
6 #20140805 13:23:05.382# 0.653367# 0.653367
Originally the velocity had the # attached to it (basically a string), so I used an excel-code to remove the last "decimal"(=LINKS(C13;LÄNGE(C13)-1), sorry for the German) and write the number in the column next to it, which I then tried to read. Maybe there's a reason, although the numbers shouldn't be strings anymore. However, when typing some random decimal numbers in some cells by myself the same problem still occurred.

Accepted Answer

Star Strider
Star Strider on 8 Nov 2014
I’m at a loss to explain the reason xlsread isn’t returning numbers, but if it’s returning a cell array of strings of numbers, something like this might be a workaround:
ns = {'2.7268'};
n = cellfun(@str2num,ns);
  2 Comments
Ben
Ben on 8 Nov 2014
That seems to work, thanks a lot!
Star Strider
Star Strider on 8 Nov 2014
My pleasure!
The spreadsheet read functions output cells, so that was a safe guess.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 8 Nov 2014
They could be strings. If they have a ' or " in front of them they will appear as numbers but be strings. You forgot to attach the workbook so we can't inspect it for you.
  2 Comments
Ben
Ben on 8 Nov 2014
I edited my original post, maybe that suffices. If not, I'll attach a workbook later. The workaround posted by Star Strider seems to work, though. Still, I'm wondering why it does this.
Image Analyst
Image Analyst on 8 Nov 2014
It's most likely doing it because of what I said. His solution is a workaround though that will "cure" it.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!