Date input from csv changing
6 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm mew to Matlab and i'm having an issue with date formats. I'm reading from a csv file, but the field of dates is going from 01/11/2012 in the csv to 01/11/0012 in matlab. I've played around with datetime, datestr and others but I can't figure out why it's reading as 0012 in the first place. The csv column is in the Date format and matlab gives me a warning saying it's being read as MM/dd/uuuu (see attached pic)
Is there a way I can get the readtable to interperate the date field as text? Then I can manually assign characters to dd/mm/yyyy?
Eventually, this will be the first of many csv's (all in the same format) being uploaded so I want to avoid changing the csv if possible.
Al the dates are actually the same for this file.
mytable = readtable(string(temp1_file));
dates = unique(mytable.Date)
dates =
datetime
01/11/0012
0 个评论
采纳的回答
Cris LaPierre
2025-3-25
The warning is telling you that the datetime format detected in the file is ambiguous. You can avoid this by specifying the format instead. You haven't shared what the data in your csv file looks like, but I'm guessing the dates are captured as 01/11/12
If so, try this.
opts = detectImportOptions(string(temp1_file));
opts = setvaropts(opts,'Date','InputFormat','dd/MM/yy');
mytable = readtable(string(temp1_file),opts);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!