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.

 채택된 답변

Star Strider
Star Strider 2014년 11월 8일

0 개 추천

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

Ben
Ben 2014년 11월 8일
That seems to work, thanks a lot!
Star Strider
Star Strider 2014년 11월 8일
My pleasure!
The spreadsheet read functions output cells, so that was a safe guess.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 11월 8일

0 개 추천

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

Ben
Ben 2014년 11월 8일
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 2014년 11월 8일
It's most likely doing it because of what I said. His solution is a workaround though that will "cure" it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

Ben
2014년 11월 8일

댓글:

2014년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by