How do I make recognise a year in a given date ?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pierre Lonfat
le 26 Fév 2018
Réponse apportée : Venkata Siva Krishna Madala
le 1 Mar 2018
I have annual data that I should repeat for the number of concerned months. This is not straightforward since the period not always starting at the beginning of the year (meaning I could simply repeat the data 12 times).
If you look at the picture you can see what result I seek to get in bold (counting the number of months). Unfortunately, I don't know how to make Matlab recognise a year from an other. IE. that 33603 belongs to 1991 and that 33634 belongs to 1992. etc etc
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170785/image.png)
Thank you so much in advance for helping me with that !
Kindest regards, Pierre
0 commentaires
Réponse acceptée
Venkata Siva Krishna Madala
le 1 Mar 2018
Hey Pierre,
Assuming you are the storing the dates as a datetime object in MATLAB you can use the year() function to extract just the year from the object.
If your dates are string than you can convert them to datatime objects. I have written a sample code for you. Refer to Convert Between Datetime Arrays, Numbers, and Text for more information.
x='23.03.93'
d=datetime('23.03.93','InputFormat','dd.MM.yy')
y=year(d)
You can also perform arithmetic operations on datetime objects. Refer to Date and Time Arithmetic for more information.
Regards,
Krishna Madala
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Time Series Objects 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!