- Open the file in the Import Tool.
- Change the delimiter to "comma" and the MeasurementTime variable should contain just the representation of the date and time.
- Click the dropdown showing "text" below the MeasurementTime identifier.
- Click on the "more date formats" and scroll to the bottom of the list where you can enter a custom format.
- Enter the option I specified as the Format when I created the datetime MeasurementTime above (without the double quotes but with the single quotes.) This uses the capability to "escape" literal character [a-zA-Z] in a format that is described in the description of the Format property on the documentation page for datetime.
- Import that variable and you should see it contains the appropriate date and time with the word 'at' between the date and time.
Import datetime in custom date format which includes junk characters
15 次查看(过去 30 天)
显示 更早的评论
I would like to import a csv file that contains a column of times in the following format,
2020-09-02T16:31:44.427Z
I am using the File Import Wizard, which can apply a custom date format to strings and read them in as datetime values. However there does not seem to be an option to ignore non-date characters like the T and Z in the string above. Is this possible to do, using the pulldown menu? If not I will read it in as text and extract the date/time components.
0 个评论
采纳的回答
Steven Lord
2020-9-2
Let's make a sample timetable.
MeasurementTime = datetime({'2015-12-18 08:03:05'; ...
'2015-12-18 10:03:17';...
'2015-12-18 12:03:13'}, ...
'Format', "yyyy-MM-dd 'at' hh:mm:ss");
Temp = [37.3;39.1;42.3];
Pressure = [30.1;30.03;29.9];
WindSpeed = [13.4;6.5;7.3];
WindDirection = categorical({'NW';'N';'NW'});
TT = timetable(MeasurementTime,Temp,Pressure,WindSpeed,WindDirection);
Write it to a file.
writetimetable(TT, fullfile(tempdir, 'mydata.txt'))
Now try to import the datetime variable from that file.
0 个评论
更多回答(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!