Note: since the yield data only comes out on weekdays, the last day I have data for the month is not necessarily the last day of the month.
How to remove daily data and leave the last day of each month
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix of daily US Yield curve spreads from 1990 to 2017. The data is daily, but I need to remove all except the last day of each month to make it monthly data. The dates are in the first column. How would I do this?
2 commentaires
Von Duesenberg
le 18 Mar 2018
A possibility would be to convert month names to numbers and identify breaks in month names (e.g. with the diff function). Then you could use these indices to extract the relevant rows.
Réponses (1)
Rik
le 18 Mar 2018
Assuming you have R2014b or later, the code below should extract the logical vector that is true for every last day of the month in you vector. This approach will only work if you have at least 2 days each month.
Data=datetime(1990,1,1):days(1):datetime(2017,12,31);
D_days=day(Data);
LastDayOfMonthIndex=[diff(D_days) 0]<0;
1 commentaire
Rik
le 26 Mar 2018
If you found this answer useful, please mark it as accepted answer. It will make it easier for other people with the same question to find an answer, as well as give me reputation points. If this didn't solve your question, please comment with what problems you are still having.
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!