Simulate a simulink model in matlab

1 view (last 30 days)
University of Oldenburg
University of Oldenburg on 10 Dec 2014
Answered: Orion on 10 Dec 2014
I try to evaluate a simulink model in matlab. Therefor I use the matlab command sim(...). I found this two pages with some information:
and also some entries on stackoverlow. But there I found only partial solutions to my problem and combining them did not work.
Here a minimal example of my problem:
The simulink model has a single input parameter which is plugged directly to a output parameter. THe input parameter is called input, the output parameter is called output. This model is named 'minimal'. For simplicity this is all.
My matlab script looks like the following:
%%Set matlab specific variables:
slCharacterEncoding('Windows-1252');
%%Set parameter
input = 1;
%%Set simulation parameter
%steps = [step_first step_last];
%%Do simulation
mdl = 'minimal';
simMode = get_param(mdl, 'SimulationMode');
cs = getActiveConfigSet(mdl);
mdl_cs = cs.copy;
set_param(mdl_cs,'AbsTol','1e-5',...
'SaveState','on','StateSaveName','xoutNew',...
'SaveOutput','on','OutputSaveName','youtNew')
evalin('base','input=1');
options=simset('SrcWorkspace','base','DstWorkspace','base');
sim(mdl,[0 1],options)
disp(yout);
%%end
disp('Simulation ended.');
As value after each simulation step I only receive 0. The input parameter is clearly not set.
What I would like to have, is a way to set the input parameter and receive and print the output parameter to the console.
It would be even better, when I can set an array of input parameters and with each simulation step the inputs are set to the corresponding value.

Answers (1)

Orion
Orion on 10 Dec 2014
You need to import your data. change the configuration parameters such as :
See attached files : the .m simulates the .mdl.
the only paramater I changed is this "Import" Option.

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!