Running Simulink simulation with input signals from matlab - I've got a working command but can't find it in documentation

3 vues (au cours des 30 derniers jours)
Hello,
I was looking for a way to run a simulink simulation programatically from matlab command with a given vector as a signal to the input block.
I couldn't find anything in help or google, but finally a friend reccomended me this command:
[tOut, xOut, yOut] = sim('model', timeVector, [], inputSignal);
Where inputSignal is a matrix with first column being a time vector and a second column of corresponding input values.
The problem is that matlab documentation doesn't say anything about using "sim" command in this way! Or at least I cannot find it. Could someone provide me with any official information about it, why does it work? And what is the third ([]) parameter about?

Réponse acceptée

Ced
Ced le 10 Mar 2016
Modifié(e) : Ced le 10 Mar 2016
Hi
You cannot find it because it's deprecated (although should still work, even in the new versions of matlab). This is the help page you are looking for:
I usually do it slightly differently: In simulink, I use an "Input Block" as an input. Then, in my script, I define a "timeseries" object.
example:
% define simulation time
t0 = 0;
tend = 10;
dt = 0.001;
t = t0:dt:tend;
% Generate unit step input
amplitude = 1;
t_step = 1; % I want a step at t = 1s
ind_vec = (t < t_step);
u = amplitude*ones(size(t));
u(ind_vec) = 0;
% create time series object
u_sim = timeseries(u,t,'Name','step_input');
% Now simulate system
% NOTE: the Input Block in your model must have "u_sim" set as parameter
sim('model')
I use a "to Workspace block" for the outputs. Just as a possible alternative.
Hope this helps.
  2 commentaires
Kuba
Kuba le 10 Mar 2016
Modifié(e) : Kuba le 10 Mar 2016
Thanks, that clarifies a lot!
But I'm surprised that Matlab doesn't support this usage of "sim" function anymore, it's really convenient. Your alternative is all right, but still less universal as you have to modify the model. (For example: I would need a different model for "trim" procedure and different for simulating it with computed trimmed inputs - whereas it's convenient to do it automatically from one script).
Unless I don't get it right - what exactly is this "Input Block" that you use, do you mean "From Workspace" block?
Ced
Ced le 10 Mar 2016
Yes, I meant the "From Workspace" block. Once you connect it, the title in the properties somehow changed to "Input Block" for me, hence the confusion. My bad.
I mean, you can pass any input you want, I just gave the step as an example. I don't really see how your case would be more generalizable.
But yes, I don't really like the new input method either. It feels like having a global variable floating around, which is evil imo. I'm sure there is a way of explicitly passing the parameter to the input block, but I never looked into that.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by