subsetting dates in a matrix

1 回表示 (過去 30 日間)
Cagdas Ozgenc
Cagdas Ozgenc 2013 年 11 月 1 日
コメント済み: Cedric 2013 年 11 月 1 日
Hello,
I have a time series in a matrix and first column is serial date numbers (up to millisecond precision), and other columns my samples. I would like to get those rows that belong to for example '12-Oct-2012'. I couldn't figure out how to write the logical operator to get a slice of this matrix. I would like to hopefully avoid some sort of slow string comparison.
Thanks in advance
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 1 日
Show the two first rows of your data
Cagdas Ozgenc
Cagdas Ozgenc 2013 年 11 月 1 日
編集済み: Cagdas Ozgenc 2013 年 11 月 1 日
735236.4590277778 1.4264e+03 1.4272e+03 1.4217e+03
735236.4597222222 1.4237e+03 1.4252e+03 1.4234e+03
735236.4604166667 1.4247e+03 1.4267e+03 1.4244e+03

サインインしてコメントする。

採用された回答

Cedric
Cedric 2013 年 11 月 1 日
編集済み: Cedric 2013 年 11 月 1 日
You already have serialized/numeric time stamps in you array, so just convert date boundaries to numeric, and compare numbers: assuming your array is named data..
lb_incl = datenum( '12-Oct-2012', 'dd-mmm-yyyy' ) ;
ub_excl = datenum( '13-Oct-2012', 'dd-mmm-yyyy' ) ;
id = data(:,1) >= lb_incl & data(:,1) < ub_excl ;
dailyMean = mean( data(id,2) ) ;
or
dailySlice = data(id,2:end) ;
  2 件のコメント
Cagdas Ozgenc
Cagdas Ozgenc 2013 年 11 月 1 日
Thanks. In this scenario this is a good option.
Cedric
Cedric 2013 年 11 月 1 日
You're welcome.

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 1 日
If A is your cell array
c1=cellstr(datestr(A(:,1),'dd-mm-yyyy'))
idx=ismember(c1,'12-10-2012')
out=A(idx,:)
  1 件のコメント
Cagdas Ozgenc
Cagdas Ozgenc 2013 年 11 月 1 日
Takes forever on my dataset of million lines. It converts all serial numbers back to string and then compares those strings. Then gets the indices. Then gets the data.
Thanks anyways

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by