%% Gain and Phase Margins of Models in an Array
% For this example, load invertedPendulumArray.mat, which contains a 3-by-3 array of inverted pendulum models. The mass of the pendulum varies as you move from model to model along a single column of sys, and the length of the pendulum varies as you move along a single row. The mass values used are 100g, 200g and 300g, and the pendulum lengths used are 3m, 2m and 1m respectively.
% \matrix{& Column\enspace1 & Column\enspace2 & Column\enspace3 \cr Row\enspace1 & 100g,3m & 100g,2m & 100g,1m \cr Row\enspace2 & 200g,3m & 200g,2m & 200g,1m \cr Row\enspace3 & 300g,3m & 300g,2m & 300g,1m}

load('invertedPendulumArray.mat','sys');
size(sys)

%
% Find gain and phase margin for all models in the array.

[Gm,Pm] = margin(sys)

% margin returns two arrays, Gm and Pm, in which each entry is the gain and phase margin values of the corresponding entry in sys. For instance, the gain and phase margin of the model with 100g pendulum weight and 2m length is Gm(1,2) and Pm(1,2), respectively.
% Copyright 2012 The MathWorks, Inc.