Derivative using datenum format vector
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Elin Ramström
le 2 Déc 2019
Réponse apportée : Steven Lord
le 2 Déc 2019
Hi everyone,
I am trying to calculate a derivative using (y2-y1)/(x2-x1) thus I am using: gradient(x) ./ gradient(t). The problem is that the vector (t) is in a datenum format therefore when I use the formula the results become incorrect as it do not respect the fact that they in reality are dates.
My intention is to have (y2-y1)/(t2-t1) where the time is in minutes (with respect to seconds as well).
How do I solve this?
0 commentaires
Réponse acceptée
Steven Lord
le 2 Déc 2019
Use the minutes function to compute the difference between two elements of a datetime array (or two datetime arrays) in terms of a number of minutes. This example is contrived, since I know what m should be, but you could use this with t1 and t2 read in from a file or obtained some other way than computation.
t1 = datetime('now');
dt = randi([30 150]) % 30 to 150 minutes
t2 = t1 + hours(dt/60);
m = minutes(t2-t1) % effectively the same as dt
0 commentaires
Plus de réponses (0)
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!