Bastian Ebeling
Bastian Ebeling

Reputation: 1130

Why does find in MATLAB return indices as double values?

The find function in MATLAB returns indices where the given logical argument evaluates true.

Thus I'm wondering, why are the returned indices of type double and not uint32 or uint64 like the biggest index into a matrix could be?

Another strange thing which might be connected to that here is, that running

[~,max_num_of_elem] = computer

returns the maximal number of elements allowed for a matrix in the variable max_num_of_elem which is also of type double.

Upvotes: 3

Views: 879

Answers (1)

Mohsen Nosratinia
Mohsen Nosratinia

Reputation: 9864

I can only guess, but probably because a wide range of functions only support double. Run

setdiff(methods('double'), methods('uint32'))

to see what functions are defined for double and not for uint32 on your version of MATLAB.

Also there is the overflow issue with integer data types in MATLAB that can introduce some hard to detect bugs.

Upvotes: 6

Related Questions