필터 지우기
필터 지우기

Problem with monthly datetime array (calmonths)

조회 수: 3 (최근 30일)
Timo
Timo 2018년 1월 9일
댓글: Timo 2018년 1월 12일
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에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by