How to obtain a value from timestamp
Afficher commentaires plus anciens
Hello everyone,
Is there any method, or way how to obtain a value for example same hour previous day ? Thanks a lot
11 commentaires
dpb
le 13 Mar 2019
See
doc datetime
Walter Roberson
le 13 Mar 2019
In particular if you have an existing datetime object, T, then T - days(1) would be the timestamp for 24 hours earlier. (Though be careful about leap seconds.)
Matthew Clark
le 13 Mar 2019
Walter Roberson
le 13 Mar 2019
What is your input data structure?
Matthew Clark
le 13 Mar 2019
Walter Roberson
le 13 Mar 2019
If you are sampling every 10 minutes then you have 6 samples per hour, times 24 hours, gives 144 samples per day. So if you are looking at load(K) then the load for 24 hours earlier is load(K-144)
Matthew Clark
le 13 Mar 2019
dpb
le 13 Mar 2019
Unless load is a time (which by the variable name it surely wouldn't appear to be or the chosen name is not very descriptive of the content) it won't be, no.
Matlab will silently cast a double to the duration after doing the arithmetic requested and return a duration but that in this case is probably not what you want.
If you have a datetime value like
>> dt=datetime(2018,11,31,23,10,0);
>> dt=dt-hours(24)
dt =
datetime
30-Nov-2018 23:10:00
>>
then the new datetime value dt _is the same time of day on Nov 30 instead of Nov 31 and is also a datetime, NOT a duration.
I'm guessing that's what you're looking for.
Walter is showing you how, if you have data collected on a 10-minute sampling period to compute the location in an array by indexing operations since there a six samples/hour at 10 minute sampling, but that's not computing the actual time, just using what is known about the storage given the sample rate.
Matthew Clark
le 13 Mar 2019
BTW NB: load is a builtin (and pretty important) Matlab function to read .mat files. Aliasing it with a variable name, while quite an appropriate name for the application, is probably not a good idea. Since ML is case-sensitive, Load or some other variation would be a likely candidate.
Digression aside, adding a duration to an energy value is then inconsistent in units and simply wrong as I presumed.
It's not clear exactly what you think that should do, but as noted, you either compute the relative position of a value in an array by knowing the offset from present position as Walter shows, or you use the actual time values and look for matching timestamps of that which you wish and then use those indices to retrieve the data.
Again, we're lacking context for how you've got the data stored so is very difficult to write any specific code and talking in generalities is fraught with confusion and imprecision when it comes to writing code.
There is a timetable class in Matlab; you might find it an appropriate container for your purposes. See
doc timetable % for details, examples, etc., ...
Walter Roberson
le 13 Mar 2019
For any given location, K, in your load data, associated with a particular time, the location (K-144) is the data for the time exactly one day earlier.
Réponses (1)
Matthew Clark
le 14 Mar 2019
0 votes
7 commentaires
Walter Roberson
le 14 Mar 2019
That would be one way of doing things. Depending what you are doing with the data, you might be able to vectorize, perhaps something like
LD = LoadData(145:end);
LD24 = LoadData(1:end-144+1);
LDdiff = LD - LD24;
Matthew Clark
le 14 Mar 2019
dpb
le 14 Mar 2019
You need to "show your work!" We're just shooting in the dark trying to quess what you've actually done and are trying to do...
But, as a general rule, yes, if you are after a set of data that includes load from any point in time and that for the same time but a day earlier, then the composite data set can only include as real data from the prior day forward--iow, a composite dataset can only be one day less than the current dataset.
The only alternative to that would be to indicate missing values by augmenting the prior day with NaN or the like but that probably will not help your estimation process to do so.
Matthew Clark
le 14 Mar 2019
Matthew Clark
le 15 Mar 2019
Modifié(e) : Matthew Clark
le 15 Mar 2019
Walter Roberson
le 16 Mar 2019
Sorry, I am not really familiar with the time based networks.
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!