Round, Ceil and Floor Matlab-datenumbers

版本 1.4.0.0 (13.6 KB) 作者: Oscar Hartogensis
round/ceil/floor Matlab datenumbers to the nearest N or multiple N of a time_unit
454.0 次下载
更新时间 2014/3/25

查看许可证

datenumRound2_OH rounds a Matlab datenumber to the nearest N or multiple N of a time_unit ('YY','MO','DD','DOY','DOW','HH','MM','SS').
datenumCeil2_OH and datenumFloor2_OH ceil and floor a Matlab datenumber to the nearest N or multiple N of a time_unit

Inspired by round2.m from the Matlab FEX.

INPUT:
datenumber : Matlab datenumber
time_unit : 'YY','MO','DD','DOY','DOW','HH','MM' or 'SS'
N : (multiple of) time_unit to round to (default: 1)
do_Nmult : 0/1; 0 --> round to N (like round.m) (default: 0)
1 --> round to multiple of N (like round2.m)
do_one : 0/1/2; 1/2 --> for time_units that count from 1 instead of 0
(i.e. 'DD',DOY' and 'MO') take N as incremental summation
starting at 1. Is only used in combination with do_Nmult=1.
1_vs_2; --> include last day of the month (1) or not (2)
eg 'DD', N=5: DD=30,5,10,15,20,25,30,1,.. for do_one=0
DD= 1,6,11,16,21,26,31,1,.. for do_one=1
(default: 0) DD= 1,6,11,16,21,26, 1,6,.. for do_one=2

OUTPUT:
datenumber : rounded Matlab datenumber

EXAMPLES:
datestr(datenumRound2_OH(datenum(2012,1,28,22,30,0),'HH',2,1))
--> 28-Jan-2012 22:00:00
datestr(datenumRound2_OH(datenum(2012,1,28,22,30,0),'HH',2,0))
--> 29-Jan-2012 02:00:00

引用格式

Oscar Hartogensis (2024). Round, Ceil and Floor Matlab-datenumbers (https://www.mathworks.com/matlabcentral/fileexchange/38167-round-ceil-and-floor-matlab-datenumbers), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Dates and Time 的更多信息
致谢

参考作品: round2

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.4.0.0

For very long datenumber-records datenumRound2_OH would give an "out of memory" error. This had to do with the unnecessary usage of diag.m, which is now replaced with a more memory friendly solution.

1.3.0.0

* Added do_one option: for time_units that count from 1 instead of 0 (i.e. 'DD',DOY' and 'MO') take N as incremental summation starting at 1
* Some small bug-fixes

1.2.0.0

solved a rounding error in intermediate time_variables that caused e.g. datestr(datenumFloor2_OH(datenum(2012,1,28,16,0,0),'HH',2,1)) to give 28-Jan-2012 14:00:00 instead of 16:00

1.1.0.0

Added acknowledgement to round2

1.0.0.0