Filter löschen
Filter löschen

Simulate a simulink model in matlab

2 Ansichten (letzte 30 Tage)
University of Oldenburg
University of Oldenburg am 10 Dez. 2014
Beantwortet: Orion am 10 Dez. 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.

Antworten (1)

Orion
Orion am 10 Dez. 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.

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by