%% Array of PID Controllers
% Create a 2-by-3 grid of PI controllers with proportional gain ranging from 1–2 across the array rows and integral gain ranging from 5–9 across columns.
% To build the array of PID controllers, start with arrays representing the gains.

Kp = [1 1 1;2 2 2];
Ki = [5:2:9;5:2:9];

%
% When you pass these arrays to the pid command, the command returns the array.

pi_array = pid(Kp,Ki,'Ts',0.1,'IFormula','BackwardEuler');
size(pi_array)

%
% Alternatively, use the stack command to build an array of PID controllers.

C = pid(1,5,0.1)           % PID controller
Cf = pid(1,5,0.1,0.5)      % PID controller with filter
pid_array = stack(2,C,Cf); % stack along 2nd array dimension

%
% These commands return a 1-by-2 array of controllers.

size(pid_array)

% All PID controllers in an array must have the same sample time, discrete integrator formulas, and dynamic system properties such as InputName and OutputName.
% Copyright 2015 The MathWorks, Inc.