Please help! Timestamp matrix problem, creating new matrices
Mostrar comentarios más antiguos
Hi all,
I'm with a problem doing a part of a program, I hope you can help me.
I have this three columns in excel;

it goes until 31-01-2012 23:45
And now I want to read them into matlab and convert them into 3 new matrix with this format;
Timestamp
01-01-2012 00:00
01-01-2012 01:00
(...)
Period
A
C
Price
11,800000
10
So basicly I want a program that read's timestamp and keep's day month year and hour (ignoring the minutes), for that period of time it needs to show the most repetitive value in periods of one hour (for example: it will give A to 00 and C to 01) and finally I want it to sum the prices for that hour (so it will sum the price at 00:15 + price at 00:30 etc.)
It will be a huge help, if you can solve me this problem.
2 comentarios
Walter Roberson
el 13 de Dic. de 2013
What if there was a 1 hour slot that had two 'D' and two 'E' period markers? Then there is no "most repetitive" period marker.
In the example you show, the Period marker is the same for everything in the first hour, and is different for the second hour but that second value is the same for the entire second hour. In the third hour, can the period again be 'A' or 'C', or is each period marker unique for an hour? Or is it cyclic, repeating at 24 hour intervals?
João
el 13 de Dic. de 2013
Respuestas (2)
Walter Roberson
el 13 de Dic. de 2013
To convert S = '01-01-2012 00:15' to '01-01-2012 00:00' then
S(end-1:end) = '00';
João
el 14 de Dic. de 2013
Editada: Walter Roberson
el 15 de Dic. de 2013
6 comentarios
Walter Roberson
el 15 de Dic. de 2013
If S is a cell array of strings, then cellfun() it.
newS = cellfun( @(in) [in(1:end-2), '00'], S, 'Uniform', 0);
Now you can group together all of the entries that have the same newS entry.
On the other hand, for this purpose it does matter whether you want to group together (:00, :15, :30, :45),(:00, :15, :30, :45), or if instead you want to group together (:15, :30, :45, :00), (:15, :30, :45, :00) Either grouping could be reasonable for different purposes, but the grouping that starts with :00 instead of starting with :15 is a little easier to compute with.
When you have your data sets, does the data in the file always start with what should be the first entry of a group, or does it sometimes start part way through a group? Are there ever any missing entries, or any extra entries? Is it every possible, for example, that the :00 routine might run a fraction of a second early and so end up with a :59 timestamp, thus giving 5 entries with the same leading hour?
João
el 15 de Dic. de 2013
Walter Roberson
el 15 de Dic. de 2013
Editada: Walter Roberson
el 15 de Dic. de 2013
Well a good way to be sure on the time extraction is to do a date conversion.
timevec = datevec(timestamps);
time_hour = timevec(:,4);
Or you might want
date_hour = timevec(:,1:4);
João
el 16 de Dic. de 2013
Walter Roberson
el 16 de Dic. de 2013
date_myway = timevec(:,[3 2 1 4]);
if your order is D Mon Y H. datevec returns in the order Y Mon D H Min S Frac
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
