removing quotes from table
显示 更早的评论
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!
采纳的回答
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 = 2x1 table
Time_UTCG_
_______________________
1 Jan 2025 00:00:00.000
1 Jan 2025 00:01:00.000
T.Time_UTCG_ = datetime(T.Time_UTCG_,'InputFormat','d MMM yyyy HH:mm:ss.SSS')
T = 2x1 table
Time_UTCG_
____________________
01-Jan-2025 00:00:00
01-Jan-2025 00:01:00
3 个评论
Hi, thank you I've attached my .csv file called data. I'm still seeing issues with just this.
Also would it be easier to start with epoc seconds and convert to datetime?
I've attached a second file with Epoch seconds in data2 in case that is easier? Ultimately want it to be in timetable format.
Thanks so much for your help.
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)
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
data = 16x4 table
Time_UTCG_ A_deg_ E_deg_ R_km_
__________ ______ ______ _____
00:00.0 59.497 18.629 11051
01:00.0 59.085 17.712 11021
02:00.0 58.69 16.797 10993
03:00.0 58.311 15.885 10968
04:00.0 57.947 14.977 10945
05:00.0 57.597 14.071 10923
06:00.0 57.261 13.168 10904
07:00.0 56.939 12.269 10887
08:00.0 56.63 11.373 10872
09:00.0 56.333 10.481 10860
10:00.0 56.048 9.592 10850
11:00.0 55.775 8.707 10842
12:00.0 55.513 7.826 10836
13:00.0 55.261 6.948 10832
14:00.0 55.021 6.074 10831
15:00.0 54.79 5.204 10832
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')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
data2 = 16x4 table
Time_EpochSec_ A_deg_ E_deg_ R_km_
______________ ______ ______ _____
0 59.497 18.629 11051
60 59.085 17.712 11021
120 58.69 16.797 10993
180 58.311 15.885 10968
240 57.947 14.977 10945
300 57.597 14.071 10923
360 57.261 13.168 10904
420 56.939 12.269 10887
480 56.63 11.373 10872
540 56.333 10.481 10860
600 56.048 9.592 10850
660 55.775 8.707 10842
720 55.513 7.826 10836
780 55.261 6.948 10832
840 55.021 6.074 10831
900 54.79 5.204 10832
data2.Time_EpochSec_ = datetime(data2.Time_EpochSec_,'ConvertFrom','epochtime','Epoch','2025-01-01')
data2 = 16x4 table
Time_EpochSec_ A_deg_ E_deg_ R_km_
____________________ ______ ______ _____
01-Jan-2025 00:00:00 59.497 18.629 11051
01-Jan-2025 00:01:00 59.085 17.712 11021
01-Jan-2025 00:02:00 58.69 16.797 10993
01-Jan-2025 00:03:00 58.311 15.885 10968
01-Jan-2025 00:04:00 57.947 14.977 10945
01-Jan-2025 00:05:00 57.597 14.071 10923
01-Jan-2025 00:06:00 57.261 13.168 10904
01-Jan-2025 00:07:00 56.939 12.269 10887
01-Jan-2025 00:08:00 56.63 11.373 10872
01-Jan-2025 00:09:00 56.333 10.481 10860
01-Jan-2025 00:10:00 56.048 9.592 10850
01-Jan-2025 00:11:00 55.775 8.707 10842
01-Jan-2025 00:12:00 55.513 7.826 10836
01-Jan-2025 00:13:00 55.261 6.948 10832
01-Jan-2025 00:14:00 55.021 6.074 10831
01-Jan-2025 00:15:00 54.79 5.204 10832
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)
data = 16x4 table
Time_UTCG_ A_deg_ E_deg_ R_km_
____________________ ______ ______ _____
01-Jan-2025 00:00:00 59.497 18.629 11051
01-Jan-2025 00:01:00 59.085 17.712 11021
01-Jan-2025 00:02:00 58.69 16.797 10993
01-Jan-2025 00:03:00 58.311 15.885 10968
01-Jan-2025 00:04:00 57.947 14.977 10945
01-Jan-2025 00:05:00 57.597 14.071 10923
01-Jan-2025 00:06:00 57.261 13.168 10904
01-Jan-2025 00:07:00 56.939 12.269 10887
01-Jan-2025 00:08:00 56.63 11.373 10872
01-Jan-2025 00:09:00 56.333 10.481 10860
01-Jan-2025 00:10:00 56.048 9.592 10850
01-Jan-2025 00:11:00 55.775 8.707 10842
01-Jan-2025 00:12:00 55.513 7.826 10836
01-Jan-2025 00:13:00 55.261 6.948 10832
01-Jan-2025 00:14:00 55.021 6.074 10831
01-Jan-2025 00:15:00 54.79 5.204 10832
Thank you Cris, very insightful.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
