Simulink: changing parameter mid-simulation

Hi all,
I am trying to run a Simulink model with 12 "In" blocks and 4 "out" blocks" using a Matlab script.
One of those 12 inputs is a variable called "input_boucle" which is initially set at value 0.
I would like the simulation to last 5 seconds and at time = 3 seconds, I want the "input_boucle" variable to switch from 0 to 1 for the remaining of the simulation.
My initial script was quite simple:
t_stop = 5;
T_s = t_stop/1000;
options = simset('SrcWorkspace','current', 'fixedstep', T_s) ;
sim('test_all_InOut_Blocks.slx',t_stop, options);
I would like to have something like this:
save_mat_file_InOut_blocks; % That's where I create my workspace with all the variables
t_stop_ouverte = 5;
T_s = t_stop_ouverte/1000;
options_boucle_ouverte = simset('SrcWorkspace','current', 'fixedstep', T_s) ;
sim('test_all_InOut_Blocks.slx',t_stop_ouverte, options_boucle_ouverte)
set_param('test_all_InOut_Blocks','SimulationCommand','pause') % But how do I specify to stop at 3 seconds?
input_Boucle.signals.values = double(0); % 1: boucle ouverte, 0: boucle fermée
set_param('test_all_InOut_Blocks','SimulationCommand','continue')
I understand that this is the way:
With the assertion having for command:
set_param(bdroot,'SimulationCommand','pause'),
disp(sprintf('\nSimulation paused.'))
But how can I integrate my inital model to this model?
Would anyone know how to solve my issue?
Thanks in advance!

 Risposta accettata

Jon
Jon il 3 Nov 2021
Modificato: Jon il 3 Nov 2021
I would just run one simulation for 5 seconds and put in a switch as shown in the first example below. Note you could probably make it even a little simpler using the second example below, but this only works because the two values you switch between happen to be 0 and 1 which correspond to logical false, true. The first approach would allow switching between any two values

5 Commenti

This looks great, thanks a lot! How do you call the block which allows me to regroup my initial model right after the assertation one please? I'll try your method right away
I'm not familiar with the assertion block. Unless I'm missing something, that is not really needed here. Just run for the whole 5 seconds and have the input switch its value using blocks.
Actually now that I have thought about it a little more there is even a simpler way, just using a step source block.
Like this:
Thank you for all your help!
Hope you are able to move ahiead with that. If that answered your question please accept the answer. That way other people with a similar problem will know there may be a solution for them too.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink in Centro assistenza e File Exchange

Prodotti

Release

R2014b

Richiesto:

il 3 Nov 2021

Commentato:

Jon
il 4 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by