How to create a time serie with daily data
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sandeep Mishra
2025-1-17
Hi @Job1003
Can you also attach the missing variable/function 'txt' and 'ts' for better debugging?
采纳的回答
Seth Furman
2025-1-17
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 个评论
更多回答(1 个)
Sandeep Mishra
2025-1-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!