I am reading data from a CSV file that contains a combination of date, numeric, and text fields. I then convert the table data to an array for calculations. The problem is the readtable is assuming the date format MM/dd/uuuu when it is recorded in the CSV file as dd/MM/uuuu.
I have attempted to convert it to a string and back but the conversion to a string is reading the date in American format and then outputing the wrong date in rest-of-the-world format. eg. 01/07/2017 in the CSV is converted to a string 07-JAN-2017 which is then converted to 07/01/2017.
Data = readtable(CSVFilePath)
TimeDate = table2array(Data(:,1))
I have also tried
TimeDate = datetime(TimeDate ,'InputFormat', 'dd/MM/uuuu')
but that also interprets a change in month as a change in day.

댓글 수: 2

Andrei Bobrov
Andrei Bobrov 2017년 7월 6일
Please attaching your data: CSV - file
Andrew Hart
Andrew Hart 2017년 7월 10일
Here you go. Thanks.

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

 채택된 답변

Steven Lord
Steven Lord 2017년 7월 10일

0 개 추천

Look at the "Read Foreign-Language Dates from Text File" example in the documentation for the readtable function. When you don't tell readtable the format of your data, it tries to determine the format on its own. If it doesn't quite get it right, you can use the 'Format' option to tell it exactly how to read the data.
That particular example uses the "%{fmt}D" specifier as shown in the "Nonnumeric fields" section of the documentation of the formatSpec input argument to the textscan function.

추가 답변 (0개)

카테고리

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

제품

질문:

2017년 7월 6일

댓글:

2017년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by