필터 지우기
필터 지우기

Time info is not read correctly by readtable

조회 수: 15 (최근 30일)
Leon
Leon 2020년 4월 8일
답변: Divya Gaddipati 2020년 4월 13일
I'm using the below command to read my Excel files (see attached for an example):
A = readtable('test.xlsx');
I notice one interesting thing:
My time column is read as NaN, when they are formatted as 'time' (like 02:45:31 PM)within Excel.
The fix is pretty simple, I open the Excel file, right click and choose "Format cell" and choose "Number" and select their decimal places. Then, everything will be read properly.
Here is my question. I have a lot of such Excel files, is there a way I can fix my Matlab code to address this issue, instead of manually going through my time columns?
Thanks!
  댓글 수: 6
J. Alex Lee
J. Alex Lee 2020년 4월 9일
Odd, readtable cannot read your 4th column at all, no matter what datatype is specified (inc. string and char). detectImportOptions decided it was a char, for me, and returned {0x0 char}s. Couldn't read in 2019b either.
But, when I copy-pasted the rows of your excel into a new excel file, readtable worked on the new file; detectImportOptions decided TIME_UTC was of type double.
I'm at my wit's end, maybe someone else can shed light on this situation. I attached the copy-pasted excel (matched the sheet name for good measure), and noticed the file sizes are different.
Walter Roberson
Walter Roberson 2020년 4월 9일
My Excel 2011 for Mac says that the original file is invalid and will not open it.

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

답변 (1개)

Divya Gaddipati
Divya Gaddipati 2020년 4월 13일
Hi,
This is a known issue and our development team is working on it.
Until this issue is resolved, please use Microsoft Excel to save this file as an "Excel Workbook (.XLS)" instead. The readtable function should work as expected on the .XLS workbook.
>> A = readtable('test.xls');
>> opts = detectImportOptions('test.xls');
>> preview('test.xls',opts)
ans =
8×4 table
Year Month Day TIME_UTC
____ _____ ___ ______________________________
2017 9 18 {'20:32:53.99999999999522700'}
2017 9 18 {'20:35:53.99999999999458800'}
2017 9 18 {'20:37:14.00000000000069775'}
2017 9 18 {'20:38:40.99999999999510950'}
2017 9 18 {'20:40:04.00000000000168875'}
2017 9 18 {'20:41:28.00000000000522950'}
2017 9 18 {'20:42:39.00000000000033900'}
2017 9 18 {'20:43:45.00000000000106275'}
Hope this helps!

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by