removing quotes from table
12 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Cris LaPierre
on 22 Apr 2024
Edited: Cris LaPierre
on 23 Apr 2024
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 Comments
Cris LaPierre
on 23 Apr 2024
Edited: Cris LaPierre
on 23 Apr 2024
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)
More Answers (0)
See Also
Categories
Find more on Data Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!