Thanks again. The table is attached.
Date/Time Processing and Formatting Issues
6 次查看(过去 30 天)
显示 更早的评论
I'm very new to MATLAB and have been reading tutorials and posts on plotting data from an external file (csv) and am having trouble processing date/time data. The CSV file has the date/time field as yyyy:ddd:hh:mm:ss.sssssssss (inculded sample below).
2022:246:10:00:02.593994140,4.44E+01
2022:246:10:00:03.592987060,-7.60E+01
2022:246:10:00:04.092987060,2.25E+02
I have tried several ways to plot the data but always run into an error when trying to convert the date/time string into date/time (I'm sure I'm missing a very basic/fundamental item), inculding different variations of u:DDD:HH:mm:ss.ms.
[data,txt,raw] = xlsread('test.csv');
x = txt{2:end,1};
y = raw(:,1) ;
dt = datetime(x,'InputFormat', 'u:DDD:HH:mm:ss.ms');
plot(dt,y)
Appreciate any help!
采纳的回答
Star Strider
2022-10-4
The 'yyyy' needs to be 'uuuu' (ISO year) to avoid problems with the conversion —
C = {'2022:246:10:00:02.593994140',4.44E+01
'2022:246:10:00:03.592987060',-7.60E+01
'2022:246:10:00:04.092987060',2.25E+02};
T = cell2table(C)
T.C1 = datetime(C(:,1),'InputFormat','uuuu:DDD:HH:mm:ss.SSSSSSSS')
.
4 个评论
Star Strider
2022-10-5
My pleasure!
The xlsread function has been superceded by others and is now ‘Not recommended’ (and may be deprecated in future releases), so I have stopped using it in MATLAB Answers for compatibility reasons. (Also, it doesn’t work with the online Run feature.) I now use readtable or readmatrix instead.
I was able to make my datetime code work after creating the appropriate vectors using compose. Given the format of your file, I doubt if it would be possible to use detectImportOptions to get the same result.
Anyway, my datetime code worked with it, so I learned something by figuring out how to create the appropriate character arrays to use with datetime in files with unusual formats.
.
更多回答(1 个)
millercommamatt
2022-10-4
dt = datetime(x,'InputFormat', 'yyyy:DDD:HH:MM:ss.SSSSSSSSS');
3 个评论
millercommamatt
2022-10-4
That's what I get for not testing this before posting. This has the correct minute part of the format string
dt = datetime(x,'InputFormat', 'yyyy:DDD:HH:mm:ss.SSSSSSSSS');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
