How can I divide a timestamp into intervals

5 次查看(过去 30 天)
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?

采纳的回答

Star Strider
Star Strider 2014-10-11
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’.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by