Hi!
I have a problem with function day. I need to get a day of a year. I use the following function from matlab documentation:
t1 = datetime(2019,5,4);
d = day(t1,'dayofyear');
and I get the following response from matlab:
''Unable to use a value of type 'datetime' as an index.''
The tricky part is that, on Friday I got this error. After few hours I closed the Matlab and re-opened it again and the function worked. But on Monday morning i tried to start the program again and the problem repeated.
Even trikcier it is because my college tried running it on his computer and it worked with no problem.
I then tried reinstaling Matlab and the thing still doesn't works.
Any ideas would be very appreciated.
Best reggards.

 Akzeptierte Antwort

Stephen23
Stephen23 am 23 Apr. 2019
Bearbeitet: Stephen23 am 23 Apr. 2019

2 Stimmen

''Unable to use a value of type 'datetime' as an index.'"
That error message makes it quite clear: you have a variable in the workspace named day. Either clear that variable or rename it, and then you will be able to use the function again.
Then you need to check your code to find where that variable is being created, and rename it there too.
"I then tried reinstaling Matlab and the thing still doesn't works. "
That is a bit extreme! Rather than jumping to conclusions that MATLAB must be buggy, start by looking in the workspace (e.g. whos) and looking at what function will be called (e.g. which).

4 Kommentare

Matija
Matija am 23 Apr. 2019
Thank you very much for answer.
I am not really fammiliar with programing nor english expressions. Saved me quite a lot of time here!
David Ebert
David Ebert am 13 Sep. 2022
Thank you thank you thank you!
David Ebert
David Ebert am 13 Sep. 2022
Saved my life.
Zari Zari
Zari Zari am 10 Okt. 2022
saved my life as well... thankss

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 23 Apr. 2019

Kommentiert:

am 10 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by