Add a datestr to duration data to get in datestr format

20 visualizzazioni (ultimi 30 giorni)
Jason
Jason il 18 Dic 2025 alle 18:28
Risposto: Steven Lord il 18 Dic 2025 alle 18:46
Hi, I have a graph where Im plotting on the x-axis time by using tic then in a loop making measurements 'Y' and performing tend=toc
I dor ecord the actual date / time at the start too.
dt = datestr(now,'dd-mmm-yyyy HH-MM-SS'); %get current dateTime
Once my loop has finished an I have a plot of all the Y's against their time of measurements (starting at 0), how can I add the "duration" onto the actual datestr, so I can have on the x-axis the actual date time.
thanks
Jason

Risposte (1)

Steven Lord
Steven Lord circa 12 ore fa
Rather than using date strings or serial date numbers, use datetime arrays.
x = 1:10;
dt = datetime(2025, 12, x);
y = x.^2;
plot(dt, y, 'o-')
If you're adding points to something like an animatedline iteratively, that works too.
figure
h = animatedline(dt(1), y(1), LineStyle = '-', Marker = 'o');
for k = 2:numel(y)
addpoints(h, dt(k), y(k));
end

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Prodotti


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by