How can I divide a timestamp into intervals

조회 수: 5 (최근 30일)
Vivek
Vivek 2014년 10월 11일
댓글: Star Strider 2014년 10월 11일
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’.
  댓글 수: 2
Vivek
Vivek 2014년 10월 11일
Thanks!
Star Strider
Star Strider 2014년 10월 11일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (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