MATLAB: How does MARGIN from Control System Toolbox 8.4 (R2009b) choose which Gain margin to display

Control System Toolbox

I am using MARGIN to display the Bode plot of my system together with information on the relevant gain and phase margin.
The documentation for MARGIN states:
"When faced with several crossover frequencies, margin returns the smallest gain and phase margins."
However, in my system I have two gain margins, 0.2 and 2.4, but MARGIN chooses to display 2.4 as the gain margin.

Best Answer

MARGIN function calls ALLMARGINS function to calculate the gain (and phase) margin of the system. When ALLMARGIN returns multiple gain margins MARGIN chooses the smallest gain by taking the smallest gain in dB, not taking the sign into account.
For the example 0.2 (-14 dB) and 2.4 (7.6 dB) that gives the latter is returned as gain margin of the system.