Undefined function 'month' for input arguments of type 'double'.

3 visualizaciones (últimos 30 días)
Dear All,
I have the error "Undefined function 'month' for input arguments of type 'double'." and cannot find the solution. I can partly solve it when I copy/paste the month.m function from "C:\Program Files\MATLAB\R2019b\toolbox\matlab\bigdata\@tall" to the current folder. But then I get the error "Undefined function 'datetimePiece' for input arguments of type 'char'." When I also copy/paste this funtion in the current folder then I get the error
"Error using datetimePiece (line 16)
Argument 1 to MONTH must be one of the following data types: datetime."
Does anyone have an idea?
Thanks,
Michael

Respuesta aceptada

Steven Lord
Steven Lord el 5 de Nov. de 2019
The month function is only defined for certain data types in MATLAB. It can be used to extract the month number from a datetime array, in which case the first input must be a datetime array or a tall array containing datetime values. It is not defined for double arrays in MATLAB.
There is a month function in Financial Toolbox for extracting the month from a serial date number or a date character vector. If that's what you're trying to call, confirm using ver that you have Financial Toolbox installed. Alternately, instead of operating on serial date numbers I encourage you to transition to using datetime arrays.
If you're looking to get a variable representing one month of time, consider using calmonths instead. You can add a calendar month created with calmonths to a datetime and it will automatically handle months having different numbers of days.
T = datetime('today')
nextMonth = T + calmonths(1) % November has 30 days
nextJanuary = T + calmonths(2) % December has 31 days
Don't try to copy functions written by MathWorks to different locations. At best they might work, but at worst they could interfere with the operation of seemingly unrelated functions or put MATLAB in a bad state on startup by preventing the MATLAB search path from initializing correctly.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by