MATLAB: Running simulink from matlab m file and then getting an output

simulink

Suppose I have simulink model called "A"and I run
simOut=sim('A');
from the script. How can I get time series of simulated variables?

Best Answer

Use set_param() on the appropriate blocks of the model to change the configuration of the model, and then sim() the model and record the results. For example,
gains = [1/10 1 2 5 10 50 100];
ngains = length(gains);
results = cell(ngains,1);
model_name = 'vdp';
block_name = 'vdp/Mu';
for K = 1 : ngains
set_param(block_name, 'Gain', sprintf('%f', gains(K)));
results{K} = sim(model_name);
end
Related Question