%% Sample Uncertain Variables in a Simulink(R) Model
% Generate random samples of uncertain variables in a Simulink(R) model. 
%%
% Open the model.

% Copyright 2015 The MathWorks, Inc.

open_system('usim_model')
%%
% The model contains three Uncertain
% State Space blocks named Unmodeled Plant Dynamics, Plant, and Sensor Gain.
% These blocks depend on three uncertain variables named |input_unc|,
% |unc_pole|, and |sensor_gain|.
%
% Use |ufind| to find all Uncertain State Space blocks and uncertain
% variables in the model.
uvars = ufind('usim_model');
%%
% Use |usample| to generate random samples of |input_unc|, |unc_pole|, and
% |sensor_gain|. Simulate the closed-loop response for each of these random
% samples.
for i=1:10;
   uval = usample(uvars); 
    sim('usim_model',10); 
end 
%%
% The MultiPlot Graph block displays the simulated responses.