Problem with monthly datetime array (calmonths)

1 次查看(过去 30 天)
Hello everybody, I am facing some strange problem when I want to create a monthly datetime array. When I start matlab and create a monthly datetime vector as shown here: https://de.mathworks.com/help/matlab/ref/ymd.html with following command
t = datetime(2013,05,31):calmonths(3):datetime(2014,06,15)
everything is fine and it produes the vector including 5 months. Afterwards I was running a script and then I tried to produce following monthly datetime array
calperiodmon=datetime(2011,01,01):calmonths:datetime(2014,12,31);
Then the error "Inputs must be scalar" occured, but I have several codes where exactly that expression is working. To check what was wrong I tried to get the output of the example mentioned before (t array above) and now it produces a 1x381 array containing each day instead of the months. Trying to get my desired output in this way:
calperiodmon=datetime(2011,01,01):calmonths:datetime(2014,12,31);
now also results in an 1x1461 array that comrpises all days of the period of interest instead of months.
I am confused, if I restart Matlab and directly produce my monthly array it works, but always after running the script and try to produce similar arrays afterwards it behaves as described above. Sure it is an option to go ahead like that and always restart matlab before running my code(s) but I would say that it is not really satisfying.
Hopefully, some of you could help me since I really have no clue what's going on :)
Greetings and thanks in advance
  3 个评论
Timo
Timo 2018-1-12
Hello Matt,
thank you for your answer :)! The output I get from your provided command is the following: calmonths is a variable. C:\Program\Files\MATLAB\R2017a\toolbox\matlab\timefun\@calendarDuration\calendarDuration.m % Shadowed calendarDuration method C:\Program Files\MATLAB\R2017a\toolbox\matlab\bigdata\@tall\calmonths.m % Shadowed tall method C:\Program\Files\MATLAB\R2017a\toolbox\distcomp\parallel\@codistributed\calmonths.m % Shadowed codistributed method C:\Program Files\MATLAB\R2017a\toolbox\matlab\timefun\calmonths.m % Shadowed
In this case there is no conflict with one of my user defined functions or do I misinterpret the output of the command? Hopefully, you can give me some advice again I would be really glad :) Thanks in advance.
Timo
Timo 2018-1-12
Forget my last comment, I didn't recognize the first line calmonths is a variable :)! Problem solved, thanks a lot for helping to recognize that stupid mistake!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by