xlsread problem with datenum

조회 수: 4 (최근 30일)
Sal
Sal 2015년 11월 1일
댓글: Sal 2015년 11월 1일
Hi all,
When importing an xls file made of two columns: the first of timestamp and the second of value, I have an error doing the datenum on the timestamp cell. Indeed, the problem is how xlsread import the excel dates. In the last value you can see that the excel date '11/1/2015 00:00:00' is truncated and thus datenum do not find the correct format. Do you know how I can convert in a fast and easy way this format?
'10/31/2015 11:59:29 PM' [159510]
'10/31/2015 11:59:34 PM' [159527]
'10/31/2015 11:59:42 PM' [159528]
'10/31/2015 11:59:43 PM' [159536]
'11/1/2015' [159537]
Thanks a lot
  댓글 수: 1
Jan
Jan 2015년 11월 1일
If you post the relevant part of the code, suggesting a modification is easier and more likely to match your needs.

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

답변 (1개)

Jan
Jan 2015년 11월 1일
You can append the trailing time string manually:
C = {'10/31/2015 11:59:29 PM'; ...
'10/31/2015 11:59:34 PM'; ...
'10/31/2015 11:59:42 PM'; ...
'10/31/2015 11:59:43 PM'; ...
'11/1/2015'};
Cropped = cellfun('length', C) < 10;
C(Cropped) = strcat(C(Cropped), {' 00:00:00 AM'});
  댓글 수: 1
Sal
Sal 2015년 11월 1일
Thanks a lot Jan,
I was looking at the function generated by the wizard and actually a solution seems to be the handle that xlsread uses. In particular:
[~, ~, raw, dates] = xlsread(workbookFile, sheetName, sprintf('A%d:B%d',startRow(1),endRow(1)),'' , @convertSpreadsheetExcelDates);
The function @convertSpreadsheetExcelDates seems to do this but I would like to not use the startRow and endRows because I do not know them before since all the files are different.
What do you think?
Thanks a lot

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by