- Load data
- Put data in two timetables
- Use synchronize
- Step 1-3 did not work? Upload the data.
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to handle variable time stamped long time series data?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello! i am working on time series data of sea water levels. one station data is in zrx format, and other is in excel(xls) format. i have to find the correlation between the two data sets in Matlab. time stamps of both files are not syncronized. and i have to correlate the data on same time stamp. please guide me, should i shift my data to timetable. and then start my analysis? or how should i start it ?
thanks in advance.
채택된 답변
jonas
2018년 10월 20일
편집: jonas
2018년 10월 20일
댓글 수: 18
bushra raza
2018년 10월 20일
Hi, thanx for the reply. i tried timetables. one data file worked fine. other data file's timestamp is like 19991101000100 , which is not understandable to timetable. how to make this value as a datetime format to be understandable for timetable. moreover, 19991101000100 is (yyyy mm dd hh mm ss)
any idea ?
per isakson
2018년 10월 20일
Try
>> datetime( '19991101000100', 'InputFormat', 'yyyyMMddHHmmss' )
ans =
datetime
01-Nov-1999 00:01:00
bushra raza
2018년 10월 20일
no its not working in table.
here is the code for creating a table and then using it further
timmTbl= readtable('Timm_Data.xlsx'); % TimmData = table2timetable(timmTbl); head(TimmTbl); the out put is :
1.9991e+13 480 ''
1.9991e+13 480 ''
1.9991e+13 481 ''
1.9991e+13 481 ''
1.9991e+13 481 ''
1.9991e+13 481 ''
1.9991e+13 481 ''
1.9991e+13 481 ''
here the first column is having datetime like 19991101000100 in original file, but it displays like 1.9991e+13.
when i write:
datetime( timmTbl(:,1), 'InputFormat', 'yyyyMMddHHmmss' );
i got following error:
Error using datetime (line 639) Input data must be a numeric or a date/time string or a cell array or char matrix containing date/time character vectors.
jonas
2018년 10월 20일
편집: jonas
2018년 10월 20일
You cant pass double data to datetime like that. You need to first convert the numbers to strings using 'num2string'. After that it should work. Just make sure the strings are formatted correctly without trailing zeros or so.
Best would be to import the data correctly from the get go. Sometimes its enough to just write
opts=detectImportOptions('filename')
And pass it to readtable
readtable(filename, opts)
Upload some sample data if it doesn't work.
jonas
2018년 10월 20일
편집: jonas
2018년 10월 21일
Importing the data with readtable gives these values
T =
11×2 table
timestamp value
______________ _____
19991101000100 480
This line converts the first row to datetime format
T.timestamp = datetime(num2str(T{:,1}),'inputformat','yyyyMMddHHmmss');
You can then convert the table to a timetable.
TT = table2timetable(T(:,2:end),'RowTimes',T.timestamp)
TT =
11×1 timetable
Time value
____________________ _____
01-Nov-1999 00:01:00 480
bushra raza
2018년 10월 21일
편집: bushra raza
2018년 10월 21일
thanx, it worked fine for a chunk of the data i sent as in book1.xlsx. but my heavy data file is not picking it.
actually, the data file to be shifted into timetable is a 2 column file in zrx format. it can be viewed in notepad. its initial lines are not s headers rather some unn-necessary text , just above the number data columns, its headers are mentioned. kindly guide is there any way to read such a file as a table and ultimately to a timetable. i am trying to save this zrx file in excel , but due to some data loss message, i am unable to proceed.
i am stuck here.any guidance would be a great help. here is the attached image of the file opened in notepad
jonas
2018년 10월 21일
편집: jonas
2018년 10월 21일
Could you upload a sample set that is more difficult to parse? Also, what release are you using? Readtable has tons of importoptions but they keep changing with every release...
One way is to type
Opts = detectImportOptions(filename)
And pass the variable Opts as the second argument of readtable. It tends to help when parsing semi-difficult formats. For more complex formats you need to adapt the importoptions, which is also quite straight forward.
jonas
2018년 10월 21일
편집: jonas
2018년 10월 21일
This works for me
opts = detectImportOptions('data.txt');
T = readtable('data.txt', opts);
T =
43×3 table
Var1 Var2 Var3
______________ ____ ____
19991101000100 480 ''
it does give an extra variable, which can easily be removed by
T(:,3)=[];
It's quite difficult to give you code for readtable, because in my experience the same code does not necessarily transfer well to other matlab versions. I can give you a solution with textscan if the above solution does not work.
bushra raza
2018년 10월 23일
Hi, i have a question regarding timetables i have two timetables, i have synchronized them. both timetables have one column each. now i need to make a data column of their difference. is there any way? here is my code of timetables and synchronize
P_Data = table2timetable(P_Tbl); AP_Data = table2timetable(AP_Tbl);
BothPressure = synchronize(P_Data,AP_Data);
tr1 = timerange('12-Aug-2015','12-Nov-2015'); P = P_Data(tr1,'Pressure'); AP = AP_Data(tr1, 'Air_pressure');
i want to calculate : Pressure - Air_pressure
any advice ?
jonas
2018년 10월 23일
Sure, this should give you the difference, assuming you have two timetables TT1 and TT2.
TTdiff = TT1{:,1} - TT2{:,1};
You could also add this as a new column in your timetable:
TT1.diff = TT1{:,1} - TT2{:,1};
You can index tables in many different ways... What you need to remember is that accessing the content of a table is done through use of curly braces {}.
Actually, this is a general rule for MATLAB. Curly braces returns the content of whatever you put in whereas normal braces return the same class as you put in.
bushra raza
2018년 10월 23일
a great help indeed. thank full to you
can you please also guide me: how can i save this calculation with timestamp in a separate data file or so?
jonas
2018년 10월 23일
Ive never done this, but you can probably use this
T = timetable2table(TT)
writetable(T, 'file.txt')
where TT is your timetable.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)