How to find something that you're not looking for?!
古いコメントを表示
Hey everyone!
So I haven written a couple matlab codes to predict the future values of some time series. Within those codes i need the following command:
start=datenum(2011,01,01,0,0,0);
finish=datenum(2011,31,12,23,0,0);
a=find(date==start);
b=find(date==finish);
The vector "date" contains dates and I want to find the exact position of the dates that I have assigned to the variables start and finish. However depending on the data I am using, sometimes there are some gaps within the dates in vector "date". For example vector "date" contains all dates from 01-01-2009 until 12-31-2013 but the dates from 12-28-2011 to 01-05-2012 are missing. Consequently if I ran this code, I would get the index of my start date (assigned to variable a) but the index of my finish date (assigned to variable b) is empty.
Is there any way to determine the closest match to the date I am looking for? For example in this case I would want matlab to tell me the exact position of the date 12-28-2011 within the vector "date" if it cannot tell me the position the the date "finish".
I would be grateful for any ideas how to work around this. Restructuring the vector "date" and filling it with the missing dates is no solution for me at the moment...
Thank you so much!!
採用された回答
その他の回答 (1 件)
per isakson
2014 年 10 月 22 日
編集済み: per isakson
2014 年 10 月 22 日
Try this
ix = find( date >= finish, 1, 'first' );
2 件のコメント
Guillaume
2014 年 10 月 23 日
My answer will give you the closest date regardless if it's before or after.
カテゴリ
ヘルプ センター および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!