I successfully used the built-in function "week.m" last week but it seems that the matlab file has now disapeared. When I try to use it (e.g. week(1)) I get the following error message: Undefined function 'week' for input arguments of type 'double'. I checked in the finance/calendar, all is there but not the week.m file nor the quarter.m..... Any idea how to recover it ?

댓글 수: 3

Matt J
Matt J 2015년 7월 14일
I've never used week(), but mysteriously, on my machine, the doc command can find it
>>doc week
but not help, which, or anything else. Weird...
Arnaud Melin
Arnaud Melin 2015년 7월 14일
Excatly, the doc exists but that's all (so at least I know I didn't dream about it).
Brendan Hamm
Brendan Hamm 2015년 7월 14일
This has to do with how classes are defined. If the class is not loaded into memory, then one cannot access its methods (it's as if they are not on the path). But you can access the documentation as the doc is not searching the MATLAB path for a file of the given name like help and which do.

댓글을 달려면 로그인하십시오.

 채택된 답변

Brendan Hamm
Brendan Hamm 2015년 7월 14일

0 개 추천

Firstly, week is indeed a function which is included in base MATLAB for versions 2014b and later. It is meant to operate on a datetime variable and not on a numeric double and therefore you get this error. You can verify that it is indeed still installed with the following command:
which week -all
This will tell you the location of all of the instances of week which MATLAB finds.
What exactly are you trying to do with the function by passing a numeric value to the function?

댓글 수: 5

Arnaud Melin
Arnaud Melin 2015년 7월 14일
In my script, I am using serial date numbers instead of datetime type. What I can't understand is that it worked perfectly yesterday... When I do what Titus says, using datetime type as argument, it works but I would have to modify everything for something that was working before.
Titus Edelhofer
Titus Edelhofer 2015년 7월 14일
편집: Titus Edelhofer 2015년 7월 14일
Hi Arnaud,
I could imagine that someone added a simple week.m that might look like
function w = week(d, varargin)
t = datetime(d,'ConvertFrom','datenum');
w = week(t, varargin{:});
If this is the case, searching your hard disk for week.m would do the trick ;-).
Titus
week never worked with Serial Date Numbers. If you wish to use this function you would have to convert your Serial Date Number to a datetime:
dNum = now % Serial Date Number
dTime = datetime(dNum,'ConvertFrom','datenum')
wk = week(dTime)
or if you prefer the use with the datenum you can use:
wk2 = weeknum(dNum)
If someone had added such a function, then it would've appeared on his search path when he called:
which week
So, I doubt this is the case. He likely either had a datetime variable and used week, or he had a serial date number and used weeknum.
Arnaud Melin
Arnaud Melin 2015년 7월 15일
I used serial date number with week, but I'll convert serial date number into datetime type and it should be alright. Thanks guys !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2015년 7월 14일
편집: Titus Edelhofer 2015년 7월 14일

1 개 추천

Hi,
EDIT: my answer below is not correct, but the comment explains what's going on.
Hmm, are you sure this is a MathWorks supplied file? I know of weekday (MATLAB) and weeknum (Financial Toolbox) but not of week ...?
Maybe you copied it from somewhere? And maybe it's just a path thing, i.e., the folder containing your week.m is not on the MATLAB search path.
Try to locate week.m on your disk and use pathtool to add the folder in MATLAB.
Titus

댓글 수: 2

Sorry, I stumbled across this myself and now (with the help of the others) remember. As long as you haven't created any datetime object, the class definition is not loaded and therefore which doesn't find it. This works:
t = datetime
t =
14-Jul-2015 16:59:24
which week
C:\MATLAB\R2015a\toolbox\matlab\timefun\@datetime\datetime.m % datetime method
Brendan Hamm
Brendan Hamm 2015년 7월 14일
Correct, which would require the class definition is loaded, but the doc command would not have this requirement.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2015년 7월 14일

댓글:

2015년 7월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by