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 Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by