![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177077/image.jpeg)
Simulate a simulink model in matlab
2 views (last 30 days)
Show older comments
I try to evaluate a simulink model in matlab. Therefor I use the matlab command sim(...). I found this two pages with some information:
http://de.mathworks.com/help/simuli.....sing-the-sim-command.html http://de.mathworks.com/help/simulink/slref/sim.html
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.
0 Comments
Answers (1)
Orion
on 10 Dec 2014
You need to import your data. change the configuration parameters such as :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177077/image.jpeg)
See attached files : the .m simulates the .mdl.
the only paramater I changed is this "Import" Option.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!