How do I plot time-stamped data from file?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have a bunch of mixed data that I need to graph (see attached file for an example).
importdata seems to bring the data in properly, but I'm having trouble plotting. As you can see in the file, many measurements are taken as a function of time. I need the time to be on the x-axis and the parameters (choose any one) on the y. I wasn't able to find examples of datetime formats using AM and PM designations, and this is obviously too much data to enter manually.
Thanks for the help.
채택된 답변
Peter Perkins
2018년 1월 9일
Reading the data in is relatively easy in recent MATLAB, although there's a couple of tricks. I'm using R2017b, earlier versions may need slightly different tweaks.
First, the file is tab delimited, with some blank lines at the top. Easiest thing is to use detectImportOptions and tell it where the variable names are:
>> opts = detectImportOptions('test.txt');
>> opts.VariableNamesLine = 3
opts =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {'\t'}
Whitespace: '\b '
LineEnding: {'\n' '\r' '\r\n'}
CommentStyle: {}
ConsecutiveDelimitersRule: 'split'
LeadingDelimitersRule: 'keep'
EmptyLineRule: 'skip'
Encoding: 'ISO-8859-1'
Replacement Properties:
MissingRule: 'fill'
ImportErrorRule: 'fill'
ExtraColumnsRule: 'addvars'
Variable Import Properties: Set types by name using setvartype
VariableNames: {'Var1', 'Var2', 'Var3' ... and 29 more}
VariableTypes: {'datetime', 'datetime', 'double' ... and 29 more}
SelectedVariableNames: {'Var1', 'Var2', 'Var3' ... and 29 more}
VariableOptions: Show all 32 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
Location Properties:
DataLine: 5
VariableNamesLine: 3
RowNamesColumn: 0
VariableUnitsLine: 0
VariableDescriptionsLine: 0
Then read the file.
>> t = readtable('test.txt',opts,'ReadVariableNames',true);
Warning: The DATETIME data was created using format 'MM/dd/uuuu' but also matched 'dd/MM/uuuu'.
To avoid ambiguity, supply a datetime format using SETVAROPTS, e.g.
opts = setvaropts(opts,varname,'InputFormat','MM/dd/uuuu');
> In matlab.io.internal.text.TableParser/readData (line 75)
In matlab.io.text.TextImportOptions/readtable (line 223)
>> head(t)
ans =
8×32 table
Date Time Rate1 Rate2 Thick_1 Thick_2 PowerEG1 HighVolt_1 HVPSEm_1 Emission1 Filament1 ISRFPower ISRFReflectedPower ISCoilCurrent ISIgnitorVoltage MFC1Flow MFC2Flow MFC3Flow GasFlowRes_4 Subst_Temp_ HeatPower ChamberTemp_ CryoTemperature1_Stage CryoTemperature2_Stage ChamberP_ ForelineP_ PumplineP_ RawFrequency1 RawFrequency2 ShutterE_Gun1 CustomerParameter Var32
____________________ ____________________ _____ _____ _______ _______ ________ __________ ________ _________ _________ _________ __________________ _____________ ________________ ________ ________ ________ ____________ ___________ _________ ____________ ______________________ ______________________ _________ __________ __________ _____________ _____________ _____________ _________________ _____
01-Dec-2017 00:00:00 09-Jan-2018 11:04:21 0 0 -1992 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.4 5.3e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:22 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.3 5.28e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:22 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.27e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:23 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.1 5.23e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:23 0.1 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.1 5.21e-05 '' 1.41e-07 0.301 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:24 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.2e-05 '' 1.41e-07 0.303 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:24 0.1 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.17e-05 '' 1.41e-07 0.304 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 09-Jan-2018 11:04:25 0 0 0 0 0 747.8 45 45 -0.31 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.1 5.14e-05 '' 1.41e-07 0.305 5.9848e+06 0 0 0
That warning is important, but I'm gonna guess that you file uses MM/dd. You will also notive that Time was read in as a datetime, with the correct time frm the file but with today's date. We can patch that up.
>> t.Time = timeofday(t.Time);
>> head(t)
ans =
8×32 table
Date Time Rate1 Rate2 Thick_1 Thick_2 PowerEG1 HighVolt_1 HVPSEm_1 Emission1 Filament1 ISRFPower ISRFReflectedPower ISCoilCurrent ISIgnitorVoltage MFC1Flow MFC2Flow MFC3Flow GasFlowRes_4 Subst_Temp_ HeatPower ChamberTemp_ CryoTemperature1_Stage CryoTemperature2_Stage ChamberP_ ForelineP_ PumplineP_ RawFrequency1 RawFrequency2 ShutterE_Gun1 CustomerParameter Var32
____________________ ________ _____ _____ _______ _______ ________ __________ ________ _________ _________ _________ __________________ _____________ ________________ ________ ________ ________ ____________ ___________ _________ ____________ ______________________ ______________________ _________ __________ __________ _____________ _____________ _____________ _________________ _____
01-Dec-2017 00:00:00 11:04:21 0 0 -1992 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.4 5.3e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:22 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.3 5.28e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:22 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.27e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:23 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.1 5.23e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:23 0.1 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.1 5.21e-05 '' 1.41e-07 0.301 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:24 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.2e-05 '' 1.41e-07 0.303 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:24 0.1 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.17e-05 '' 1.41e-07 0.304 5.9848e+06 0 0 0
01-Dec-2017 00:00:00 11:04:25 0 0 0 0 0 747.8 45 45 -0.31 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.1 5.14e-05 '' 1.41e-07 0.305 5.9848e+06 0 0 0
It's possible that you want the date and time combined, also easy. Make it a timetable.
>> t.Time = t.Date + t.Time;
>> t.Date = [];
>> tt = table2timetable(t);
>> head(tt)
ans =
8×30 timetable
Time Rate1 Rate2 Thick_1 Thick_2 PowerEG1 HighVolt_1 HVPSEm_1 Emission1 Filament1 ISRFPower ISRFReflectedPower ISCoilCurrent ISIgnitorVoltage MFC1Flow MFC2Flow MFC3Flow GasFlowRes_4 Subst_Temp_ HeatPower ChamberTemp_ CryoTemperature1_Stage CryoTemperature2_Stage ChamberP_ ForelineP_ PumplineP_ RawFrequency1 RawFrequency2 ShutterE_Gun1 CustomerParameter Var32
____________________ _____ _____ _______ _______ ________ __________ ________ _________ _________ _________ __________________ _____________ ________________ ________ ________ ________ ____________ ___________ _________ ____________ ______________________ ______________________ _________ __________ __________ _____________ _____________ _____________ _________________ _____
01-Dec-2017 11:04:21 0 0 -1992 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.4 5.3e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 11:04:22 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.3 5.28e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 11:04:22 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.27e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 11:04:23 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.1 5.23e-05 '' 1.41e-07 0.3 5.9848e+06 0 0 0
01-Dec-2017 11:04:23 0.1 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.24 0 27.1 0 0 32.8 6.1 5.21e-05 '' 1.41e-07 0.301 5.9848e+06 0 0 0
01-Dec-2017 11:04:24 0 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.2e-05 '' 1.41e-07 0.303 5.9848e+06 0 0 0
01-Dec-2017 11:04:24 0.1 0 0 0 0 747.8 45 45 -0.32 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.2 5.17e-05 '' 1.41e-07 0.304 5.9848e+06 0 0 0
01-Dec-2017 11:04:25 0 0 0 0 0 747.8 45 45 -0.31 0 0 0 0 0 -0.64 -0.23 0 27.1 0 0 32.8 6.1 5.14e-05 '' 1.41e-07 0.305 5.9848e+06 0 0 0
Now just plot, either one at a time
plot(tt.Time,tt.Rate1)
or several at a time
plot(tt.Time,tt(:,{'Rate1' 'Rate2'}}))
댓글 수: 1
Thanks, Peter. This helped a lot. I didn't really know how to deal with this poorly formatted file. I think your answer boiled down to:
opts = detectImportOptions(filename);
opts.VariableNamesLine = 3;
t = readtable(filename,opts,'ReadVariableNames',true);
t.Time = timeofday(t.Time);
followed by some plotting. The ttplot looks really good, too. I'll definitely check that out.
Really appreciate it. Thanks again.
Edit: By the way, everything worked in 2017a.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Calendar에 대해 자세히 알아보기
참고 항목
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)
