removing quotes from table
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
puccapearl
am 22 Apr. 2024
Kommentiert: puccapearl
am 26 Apr. 2024
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 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 22 Apr. 2024
Bearbeitet: Cris LaPierre
am 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 Kommentare
Cris LaPierre
am 23 Apr. 2024
Bearbeitet: Cris LaPierre
am 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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!