File Exchange

image thumbnail

Round, Ceil and Floor Matlab-datenumbers

version 1.4.0.0 (13.6 KB) by Oscar Hartogensis
round/ceil/floor Matlab datenumbers to the nearest N or multiple N of a time_unit

0 Downloads

Updated 25 Mar 2014

View Version History

View License

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

Cite As

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

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: round2

Community Treasure Hunt

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

Start Hunting!