How to create a time serie with daily data
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Job1003
le 17 Jan 2025
Réponse apportée : Seth Furman
le 17 Jan 2025
Please i am trying to make a time series with daily financial datas.
The datas are observed daily except on weekends.
My main concern is that i am trying to set a moving starting (02 of january 2017) date with the function dattetime but i am having an error message. Please could you tell me what i did wrong?
M

Also , can you tell me how i can account for the weekly two days break in the time series.

Regards
1 commentaire
Sandeep Mishra
le 17 Jan 2025
Hi @Job1003
Can you also attach the missing variable/function 'txt' and 'ts' for better debugging?
Réponse acceptée
Seth Furman
le 17 Jan 2025
Use isweekend to remove weekends from your datetime series.
You'll also want to make sure you use caldays (calendar days) instead of days (fixed-length days) when constructing your datetime series.
% Create datetime series
startDate = datetime(2017,1,2,Format="eeee uuuu-MM-dd")
dt = (startDate:caldays(1):startDate+caldays(30))'
% Remove weekends from datetime series
dt(isweekend(dt)) = []
% Same result displayed in French
string(dt,"eeee uuuu-MM-dd","fr_FR")
Aside: Creating datetimes from localized text timestamps
I noticed that your comment says % start='02-janv-2017'. It's also worth noting that you can create datetimes from localized text timestamps. It's a good idea to specify the Locale Name-Value pair when doing this, so that your code will run on machines running MATLAB in different locales.
datetime("02-janv-2017",Locale="fr_FR")
0 commentaires
Plus de réponses (1)
Sandeep Mishra
le 17 Jan 2025
Hi Job1003,
I noticed that you are encountering an error message related to the use of the 'strrep' function in MATLAB
The root cause of the issue arises from passing an incorrect input for the 'str' parameter in the 'strrep' MATLAB function, which must be a character array.
You can refer to the following example code snippet using ‘strrep’ MATLAB function:
% Correct input - Willn't thorw any error
data = {'123', 'hello', '456', 'world'};
strrep(data, 'o', 'a')
% Wrong input - Will throw the same error
data = {123, 'hello', 456, 'world'};
strrep(data, 'o', 'a')
Refer to the following MATLAB Documentation to learn more about ‘strrep’ function: https://www.mathworks.com/help/releases/R2024b/matlab/ref/strrep.html
I hope this helps you!
0 commentaires
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!