How to find something that you're not looking for?!
Mostra commenti meno recenti
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!!
Risposta accettata
Più risposte (1)
per isakson
il 22 Ott 2014
Modificato: per isakson
il 22 Ott 2014
Try this
ix = find( date >= finish, 1, 'first' );
2 Commenti
Guillaume
il 23 Ott 2014
My answer will give you the closest date regardless if it's before or after.
Categorie
Scopri di più su Time Series Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!