MATLAB Indexing type dependence (bug?)
Show older comments
Please see this strange example, where the datatype (single vs double) of the starting index affects how many data points are returned:
y = rand(67347456+50,1);
y = single(y);
N = single(50);
size(y(N+1:end))
MATLAB returns: >> 67347454 1 (incorrect, missing 2 elements)
size([N+1:length(y)])
MATLAB returns: >> 1 67347456 (which is correct)
and
size(y(double(N)+1:end))
MATLAB returns >> 67347456 1 (also correct)
Other datatypes like uint32 also work fine.
Please help me understand: If N is only 50, what does it matter to the indexing whether it is a single or a double? Also, aren't these ending index values well within the presicion of single?
Accepted Answer
More Answers (1)
eps(single(67347456+50))
single precision numbers are 8 apart by the time of 67347456
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!