- 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 件)
参考
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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)