Why is the maximum length of a datetime array 142?

Hello,
I am trying to initialize a vector of datetime arrays and I can't go beyond a length of 142. Why is that? Is there a workaround?
Here's my code:
datetime_array = NaT(1,length(myTimeStamps));
for i=1:length(datetime_array)
datetime_array(i,:) = datetime(myTimeStamps(i,:);
end
Error: Index in position 1 exceeds array bounds (must not exceed 142).
Thank you,
Lindsey

3 Comments

Be careful with length() as it is the maximum dimension, not the number of rows necessarily. Your array might be 142 by something larger than 142.
Datetime array can be much longer than 142. This one below is 10,000 timestamps long.
datetime(1950,1:10000,1)
What is stored in myTimeStamps? Could your provide an example? Perhaps one of them is empty.
Thank you all for your feedback! i see my issue.

Sign in to comment.

 Accepted Answer

The ‘142’ value is most likely the row size of the datetime array in your code, and you are apparently addressing it beyond that limit.

4 Comments

Hmmm I was thinking that the 142 might be the number of columns in myTimeStamp. As Walter pointed out, length() seems to have returned a value greater than 142 and since the loop is row-wise and fails, it must have less than 142 rows.
You all above are correct. I have committed a really basic error regarding array dimensions which is causing this problem. Thank you for taking the time nonetheless!
The morale of the story is never use length. If you mean the length of a vector, use numel, and if you're operating on a matrix, use size with an explicit dimension.

Sign in to comment.

More Answers (0)

Products

Asked:

LMA
on 22 Jul 2019

Commented:

LMA
on 23 Jul 2019

Community Treasure Hunt

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

Start Hunting!