Do you know the features allowing to create a time vector and necessary for timeseries?
Datetime
datetime represents a point in time.
How to write this date and time November 29, 2023 at 10:05:23
with datetime ?
dt = datetime(2023, 11, 29, 10, 5, 23)
or
dt = datetime("November 29, 2023 10:05:23", "InputFormat", "MMMM dd, yyyy HH:mm:ss")
Note that datetime()
returns the current date and time.
Duration
duration represents a duration of time in hours, minutes, and seconds.
Write 10 hours 35 minutes and 22 seconds
with duration:
d = duration(10, 35, 22)
Calendarduration
calendarDuration represents a duration of time in years (calyears), months (calmonths), and days (caldays).
Create a calendarDuration of 3 months
c = calendarDuration(0, 3, 0)
Mix time types
Create a regular datetime vector with one hour time step:
dt1 = datetime(2023, 10, 25, 10, 5, 23)
dt2 = datetime(2023, 10, 25, 15, 30, 0)
dt = dt1:hours(1):dt2
For a regular datetime vector with three months time step:
dt = datetime(2023, 10, 25):calmonths(3):datetime(2024, 3, 31)
How many days until Christmas ?
d1 = datetime(2023, 12, 25)
d2 = datetime("today")
d = d1 - d2
d = days(d)
close(winsid())
d1 = datetime(2023, 12, 25);
d2 = datetime("today");
if d1 < d2 then
disp("xmas is over!");
return
end
d = d1 - d2;
d = days(d);
str = "J - " + string(d);
f = figure("figure_name","Christmas countdown", ...
"background", color(187,11,11), ...
"figure_position", [928, 305], ...
"axes_size", [630 670], ...
"visible", "off", ...
"menubar_visible", "off", ...
"toolbar_visible", "off", ...
"infobar_visible", "off", ...
"icon", "scilab", ...
"resize", "off", ...
"dockable", "off");
x = [0 6 5 5.5 4.5 5 4 4.5 3.5 4 3 2 2.5 1.5 2 1 1.5 0.5 1 0];
y = [0 0 1.5 1.5 3 3 4.5 4.5 6 6 8 6 6 4.5 4.5 3 3 1.5 1.5 0];
xfpoly(x, y, color(9,82,40))
p = scatter(3, 8, 2500, color(212, 175, 55), "p", "markerBackground", color(212,175,55));
xstring(1.7, 0, string(d2));
x = gce();
x.font_size = 6;
x.font_style = 2;
x.font_foreground = color(187,11,11);
xstring(1.5, 1, str);
x = gce();
x.font_size = 11;
x.font_style = 2;
x.font_foreground = color(187,11,11);
xfpoly([2.5 3.5 3.5 2.5 2.5], [-1 -1 0 0 -1], color(88, 41, 0));
a = gca();
a.data_bounds = [-0.5 -1.5;6.5 10];
title("Xmas is coming!!", "fontsize", 5, "fontname", 2, "color", color(255,255,255), "position", [1.5 10.5]);
plot([0 0.5 1 1.5 2 4 4.5 5 5.5 6], [0 1.5 3 4.5 6 6 4.5 3 1.5 0], "o", "markerFaceColor", color(140, 10, 10), "markerEdgeColor", color(140, 10, 10), "markerSize", 11);
c = rand(1000, 1)*8 - 1;
b = rand(1000, 1)*12 - 2;
scatter(c(1:200), b(1:200), 50, color(212, 175, 55), "*")
a.axes_visible = "off";
a.filled = "on";
a.background = color(255,255,255);
e = gce();
e = e.children;
f.visible = "on";
for i = 2:5
idx = 200*(i-1)+1:200*i;
data = [c(idx), b(idx)];
for j = 1:200
e.data(j,:) = data(j,:);
sleep(10)
end
end
As usual, don’t hesitate to share with us your use cases and issues.