MATLAB: Do I receive different results when I use RANK function with single precison values

MATLABprecisionranksingle

When I use this:
vidObj = mmreader('xylophone.mpg');
rank(single(M))
M = read(vidObj);
[m1,m2,m3,m4] = size(M);
M = reshape(M,[m1*m2 m3*m4]);
r = rank(double(M))
I get this result:
ans = 45
But when I do this with double precison values I get a different result.
>> rank(double(M))
ans =
423
How can I get similar results as double precision?

Best Answer

The code used to calculate RANK function is sensitive to the tolerance value. the tolerance for single precision is much higher that what we get for double.
The workaround to get similar results is to pass a similar value of the tolerance as that used in the double precision case.
s = svd(double(M))
tol = max(size(double(M))) * eps(max(s))
rank(single(M), tol)