%% Sample Multiple Parameters in Tunable Model
% Create a model with a pole at s = a and a gain of b*c, where a, b, and c are tunable scalars.

a = realp('a',1);  
b = realp('b',3);  
c = realp('c',1);
G = tf(b*c,[1 a]);

%
% Pick 5 samples for a and 3 samples for (b,c) pairs. Evaluate G over the corresponding 5-by-3 grid of (a,b,c) combinations.

as = 0.8:0.1:1.2;
bs = 2:4;
cs = [0.5 1 1.5];
Gs = sampleBlock(G,'a',as,{'b','c'},{bs,cs});

%
% Grouping the values for b and c in cell arrays causes sampleBlock to treat them as the (b,c) pairs, (2,0.5), (3,1), and (1,5). Gs is a 5-by-3 array of state-space models, in which a varies along the first dimension and  (b,c) varies along the second dimension. Thus, for example, Gs(:,:,3,2) corresponds to a = 1, (b,c) = (3,1).
% A step plot shows a set of responses for each of the three (b,c) pairs. Each set contains a response for each of the five a values.

stepplot(Gs)

%
% If you do not group the values, sampleBlock replaces all values independently, resulting in a 5-by-3-by-3 model array.

GsInd = sampleBlock(G,'a',as,'b',bs,'c',cs);
size(GsInd)

% For example, in GsInd, Gs(:,:,3,2,1) is a model with a = 1, b = 3, and c = 0.5.
% Copyright 2012 The MathWorks, Inc.