removing quotes from table
조회 수: 13 (최근 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!