removing quotes from table

12 visualizaciones (últimos 30 días)
puccapearl
puccapearl el 22 de Abr. de 2024
Comentada: puccapearl el 26 de Abr. de 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!

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 22 de Abr. de 2024
Editada: Cris LaPierre el 23 de Abr. de 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 = 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 comentarios
Cris LaPierre
Cris LaPierre el 23 de Abr. de 2024
Editada: Cris LaPierre el 23 de Abr. de 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)
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.
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.
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
puccapearl
puccapearl el 26 de Abr. de 2024
Thank you Cris, very insightful.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Preprocessing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by