Simulate a simulink model in matlab

조회 수: 1 (최근 30일)
University of Oldenburg
University of Oldenburg 2014년 12월 10일
답변: Orion 2014년 12월 10일
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.

답변 (1개)

Orion
Orion 2014년 12월 10일
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.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by