将日期转换为最接近的月末日期 MATLAB
我需要将日期数字转换为最接近的月末日期。我找到了一个在线链接,但对于大型矩阵来说效率非常低(位于 http://www.mathworks.com/matlabcentral/fileexchange/26374-round-off-dates-and-times)。 Matlab(Financial Toolbox
)是否有内置函数?我找不到它。
date_in = 734421 ;
somefunction(date_in) --> Sept 2010
谢谢!
I need to convert a datenumber to its closest end-of-month date. I found an online link but it is very inefficient for a large matrix (at http://www.mathworks.com/matlabcentral/fileexchange/26374-round-off-dates-and-times). Does Matlab (Financial Toolbox
) has an inbuilt function for this? I couldn't find it.
date_in = 734421 ;
somefunction(date_in) --> Sept 2010
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,听起来您是在询问给定日期是否接近上个月或下个月。如果使用函数 EOMDAY 来查找,则可以大大简化所涉及的逻辑月底的日期和ADDTODATE 来移动当前月份向上或向下 一。以下是一个以日期数字作为输入的示例函数:
Basically, it sounds like you are asking for whether a given date is closer to the preceding or following month. You can greatly simplify the logic involved if you use the functions EOMDAY to find the date for the end of the month and ADDTODATE to shift the current month up or down by one. Here's an example function that takes a date number as input:
我之前的版本有一些错误。这是合并到函数中的逻辑。它还检查月份并相应更新。
示例
1.2.3.4
.
:
I had some errors in my previous version. Here's the logic incorporated into a function. It also checks for the month and updates accordingly.
EXAMPLES:
1.
2.
3.
4.