How does max choose the answers when there are two identical values in a vector
1 view (last 30 days)
Show older comments
xueqi on 4 Jan 2015
Commented: Stephen23 on 4 Jan 2015
Could you help me with clarify this mystery please? I am using the following code to find the maximum value and its index in a vector
In matlab documentation, it says max return the first value when there are identical values in the the vector. As the values are identical, I suppose the statement means max return the index of the first maximum value. But I find sometimes this does not seem to be true. For example, I have
rdeus=[-100000 -100000 -100000 -100000 -100000 -100000 0.848202365959724 0.849479878997915 0.849479878997915 -100000 -100000 -100000 0.848158759181734]
Notice we have rdeus(8)=rdeus(9). But when I run the max code, I get the bestcol=9. Could you offer me some advice about why this happens?
Edited: Stephen23 on 4 Jan 2015
It works fine for me:
>> rdeus = [-100000,-100000,-100000,-100000,-100000,-100000,0.848202365959724,0.849479878997915,0.849479878997915,-100000,-100000,-100000,0.848158759181734];
>> [C,I] = max(rdeus)
I suspect that your rdeus(8) and rdeus(9) are not really as similar as you think they are. Are the values generated somewhere else, or defined only at the creation of the matrix rdeus ?
Are they identical? (they are for me)
Does that resolve your situation? If it does, clicking "Accept" is always appreciated. If it doesn't, please explain what remains unclear.
More Answers (0)
Find more on Logical 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!