What is the data type of the output of the length function?

2 views (last 30 days)
Why not indicated in the description? http://www.mathworks.com/help/matlab/ref/length.html
I guess it is double, but why? Length is always an integer value!

Accepted Answer

Guillaume
Guillaume on 13 Jun 2016
The default data type in matlab is double, not integer as in most compiled languages. array lengths, array indices, etc. are all stored as double.
Note that all integers up to flintmax (~9e15) can be accurately stored as double so it's not an issue at the moment. It'll be a while before computers have enough memory for it to become a problem.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 13 Jun 2016
length(A) is always integer value, but the greatest integer value, is uint64(2^64-1). The length of an array could be greater then this value
  2 Comments
Guillaume
Guillaume on 13 Jun 2016
"The length of an array could be greater then this value"
Hardly, even if the array took only one byte per elements, you're in the exabyte realm. You won't find a computer with that kind of storage (and I doubt matlab could cope with it anyway).
Azzi Abdelmalek
Azzi Abdelmalek on 13 Jun 2016
You are right, I didn't realize that the number 2^64 is too big!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!