How can I divide a timestamp into intervals

5 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Star Strider
Star Strider il 11 Ott 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’.

Più risposte (0)

Categorie

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

Community Treasure Hunt

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

Start Hunting!

Translated by