Bug in max function?

The max function in Matlab gives unexpected results.
When I type
max(double(1000), uint8(1))
matlab gives the result
ans = 255
It looks like the double is silently converted to an uint8, which in that case would have the value 255, and is thus returned as the maximum. It seems more sensible to me to automatically convert all numbers to the largest number class.
Is this a bug or is this behaviour documented somewhere?

 采纳的回答

James Tursa
James Tursa 2012-3-6

1 个投票

Documented behavior. When combing double with lesser classes (single, uint8, int32, etc) the conversion is done to the lesser class. This has been discussed before in this forum.

1 个评论

Thanks for the quick answer.
However, this feature has caused me to spend some time figuring out why the following was wrong:
image = imread(file_name);
histo = hist(image(:), linspace(0, 360, N));
with the error:
??? Error using ==> histc
Edge vector must me monotonically non-decreasing.
Error in ==> hist at 92

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Time Series Events 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by