%% Sample Uncertain Elements to Create Arrays
% A common way to generate an array is to sample the uncertain elements of an uncertain object. This example shows how to generate arrays by taking random samples of a umat uncertain matrix that has two uncertain elements. (To generate arrays by sampling at specific values, use usubs.)
% Create an uncertain matrix.

a = ureal('a',4); 
b = ureal('b',2);
M = [a b;b*b a/b;1-b 1+a*b]

%
% Sample the uncertain real parameter b in the matrix M, at 20 random points within its range.

[Ms,bvalues] = usample(M,'b',20);

%
% This results in an array of 20 3-by-2 umat matrices, with only one uncertain element, a. The uncertain element b of M has been sampled out, leaving a new array dimension in its place.

Ms

%
% Additionally, bvalues is a structure containing the corresponding sampled values of b.

bvalues

%
% Next, sample the remaining uncertain real parameter a in the matrix Ms. This removes the second uncertain block, resulting in a 3-by-2-by-20-by-15 double.

[Mss,avalues] = usample(Ms,'a',15);
size(Mss)

%
% You can also sample multiple parameters at once. The following operation returns Mss1, which is identical to Mss.

[Mss1,values] = usample(M,'b',20,'a',15);

%
% Rather than sampling each variable (a and b) independently, generating a 20-by-15 grid in a 2-dimensional space, you can sample the two-dimensional space directly. Sample the 2-dimensional space with 800 points.

[Ms2d,values] = usample(M,{'a' 'b'},800);

%
% Ms2d is a 3-by-2-by-800 umat array, where each entry corresponds to a different randomly selected (a,b) pair. The structure array values contains these (a,b) values.

values

% Copyright 2012 The MathWorks, Inc.