removing quotes from table
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
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 件のコメント
puccapearl
2024 年 4 月 23 日
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.
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)
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
puccapearl
2024 年 4 月 26 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
