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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
