How can I divide a timestamp into intervals

5 vues (au cours des 30 derniers jours)
Vivek
Vivek le 11 Oct 2014
Commenté : Star Strider le 11 Oct 2014
I have a file with time stamps from 1996 that I have loaded to a matrix. I want to add customized intervals of the day to each row as 'text' or as 'key' 1/2/3/4 etc based on following zoning (early morning 12 AM - 8 AM, morning 8 - 12, afternoon etc.)
How can I achieve this is Matlab?

Réponse acceptée

Star Strider
Star Strider le 11 Oct 2014
This works:
% Create Data
nw = now;
dn = nw + [0:48]'/24; % Column Vector Of Date Numbers
ds = [0 8:4:24]/24; % Day Segments
df = rem(dn,1); % Fractional Parts Of Date Numbers
for k1 = 1:size(dn,1)
tc(k1,:) = find(df(k1)>ds, 1, 'last'); % Time Categories
end
It depends on the dates and times being converted into date numbers (with datenum) in column vector ‘dn’. Then it strips out the fractional part of the date numbers in ‘df’ and uses the loop to compare them to the vector of day segments (in vector ‘ds’) in the loop, and assigns each to the time category in column vector ‘tc’. The loop seems to be the easiest way to do it.
The input to the routine is the column vector of date numbers ‘dn’, and the output is the column vector of time categories ‘tc’.
  2 commentaires
Vivek
Vivek le 11 Oct 2014
Thanks!
Star Strider
Star Strider le 11 Oct 2014
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by