Why do the MIN and MAX functions not ignore NaN values inside a matrix of single precision values within MATLAB 6.5 (R13)?

20 views (last 30 days)
Why do the MIN and MAX functions not ignore NaN values inside a matrix of single precision values within MATLAB 6.5 (R13)?
The help files for the MIN and MAX functions state that NaN values are ignored. This is not actually the case for vectors of single precision values.
To reproduce this behavior:
a = [8 6 10 NaN 2 4 3];
b = single(a);
min(b),max(b)
This produces the results:
ans =
NaN
ans =
NaN

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This has been verified as a bug in MATLAB 6.5 (R13) in the way that the MIN and MAX functions handle vectors of single precision values involving NaN elements.
Currently, to work around this issue, try removing all NaN values from the vector. For example,
a = [8 6 10 NaN 2 4 3];
b = single(a);
c = b;
c(isnan(c)) = [];
min(c),max(c)

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!