removing quotes from table
15 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a table with gregorian time that loads as having single quotes around it. This is giving me issues when I want to do table2timetable.
How do I remove the quotes so I can convert to timetable?
Thanks!
0 个评论
采纳的回答
Cris LaPierre
2024-4-22
编辑:Cris LaPierre
2024-4-23
The quotes inidcate the values are character arrays, Convert your times to datetimes.to remove the quotes.
It's best to do that at the time you import your data.using import options.
opts = detectImportOptions('filename.txt');
opts = setvartype(opts, 'Time_UTCG_','datetime')
opts = setvartopts(opts,'Time_UTCG_','InputFormat','d MMM yyyy HH:mm:ss.SSS');
TT = readtimetable('filename.txt',opts)
There may be more. Please attach your file to your post using the paperclip icon for an answer tailored to your data.
You can also convert your table as is if you choose.
Time_UTCG_ = ['1 Jan 2025 00:00:00.000';'1 Jan 2025 00:01:00.000'];
T = table(Time_UTCG_)
T.Time_UTCG_ = datetime(T.Time_UTCG_,'InputFormat','d MMM yyyy HH:mm:ss.SSS')
3 个评论
Cris LaPierre
2024-4-23
编辑:Cris LaPierre
2024-4-23
It looks like your time is actually elapsed time. In that case, I would use a duration instead of a datetime. The date is meaningless unless there is more information you have not shared.
opts = detectImportOptions('data.csv');
opts = setvartype(opts,'Time_UTCG_','duration');
opts = setvaropts(opts,'Time_UTCG_','InputFormat','mm:ss.S');
data = readtable('data.csv',opts)
Epoch seconds could also be used, but you must also define the epoch (starting date).Assuming that is Jan 1, 2025 (based on the data shown in your question), you could do this.
data2 = readtable('data2.csv')
data2.Time_EpochSec_ = datetime(data2.Time_EpochSec_,'ConvertFrom','epochtime','Epoch','2025-01-01')
Of course, if you have the epoch and a duration, you could just add them together.
data.Time_UTCG_ = data.Time_UTCG_ + datetime(2025,1,1)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!