필터 지우기
필터 지우기

Fill the column with pre-defined time intervals

조회 수: 3 (최근 30일)
Damith
Damith 2015년 2월 20일
댓글: Damith 2015년 2월 25일
Hi,
I need to fill the column A below with pre-defined time intervals for each day. For example, Jan 1 1998
1/1/1998 0:00
1/1/1998 3:00
1/1/1998 4:00
1/1/1998 6:00
1/1/1998 9:00
1/1/1998 10:00
1/1/1998 12:00
1/1/1998 15:00
1/1/1998 16:00
1/1/1998 18:00
1/1/1998 21:00
1/1/1998 22:00
1/2/1998 0:00
A=
1/1/1998 0:00
1/1/1998 4:00
1/1/1998 6:00
1/1/1998 10:00
1/1/1998 12:00
1/1/1998 16:00
1/1/1998 18:00
1/1/1998 22:00
1/2/1998 0:00
1/2/1998 4:00
1/2/1998 6:00
1/2/1998 12:00
1/2/1998 18:00
1/3/1998 0:00
1/15/1998 18:00
1/16/1998 0:00
1/16/1998 6:00
1/16/1998 12:00
1/16/1998 18:00
1/17/1998 0:00
1/17/1998 6:00
1/17/1998 12:00
1/17/1998 18:00
1/18/1998 0:00
1/18/1998 6:00
1/18/1998 12:00
1/18/1998 18:00
1/19/1998 0:00
1/19/1998 6:00
1/19/1998 12:00
1/19/1998 18:00
1/20/1998 0:00
1/20/1998 6:00
1/20/1998 12:00
1/20/1998 18:00
1/21/1998 0:00
1/21/1998 6:00
1/21/1998 12:00
1/21/1998 18:00
1/22/1998 0:00
1/22/1998 6:00
1/22/1998 12:00
1/22/1998 18:00
1/23/1998 0:00
1/23/1998 6:00
1/22/1998 10:00
1/22/1998 12:00
1/22/1998 18:00
1/22/1998 22:00
1/23/1998 0:00
Is there a way to this MATLAB?
Thanks in advance.

채택된 답변

Star Strider
Star Strider 2015년 2월 20일
One way to do it:
D0 = datenum([1998 01 01]);
DT = 1/24; % Days/Hour
DM = eomday(1998,01); % Days In January
DV = D0 + cumsum([0; ones(24*DM,1)*DT]);
Jan1998 = datestr(DV(1:end-1), 'mm/dd/yyyy HH:MM');
Result = [Jan1998(1:5,:); Jan1998(end-4:end,:)] % Check Result
produces:
Result =
01/01/1998 00:00
01/01/1998 01:00
01/01/1998 02:00
01/01/1998 03:00
01/01/1998 04:00
01/31/1998 19:00
01/31/1998 20:00
01/31/1998 21:00
01/31/1998 22:00
01/31/1998 23:00
The ‘Result’ variable just looks at the first and last 5 entries.
  댓글 수: 12
Damith
Damith 2015년 2월 21일
No worries. Thanks.
Damith
Damith 2015년 2월 25일
Star,
I have simplified the table now. Can you help me a way to this. I think it should be easy now.
https://www.mathworks.com/matlabcentral/answers/180349-select-rows-from-table-and-interpolate
Thanks in advance.

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

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