Changing block parameter from MATLAB code seems to need 'pause'?

1 view (last 30 days)
I'm trying to change a value in a Simulink from my code using the set_param function. I'm using a very simple code:
modelName = 'Simple_Model';
open(modelName)
set_param(modelName,'SimulationCommand','start'); % Start the model
for i=1:1:10,
set_param([modelName '/Constant'],'value',num2str(i)); % Change the value
tic, while toc<1, end; % Wait 1s
end
set_param(modelName,'SimulationCommand','stop');
The simulations simply pushes the constant value to workspace variable. However, the simulation ends with no errors but doesn't return any value. I've found out that when I change the delay line from
tic, while toc<1, end;
to
pause(1);
Which supposed to do the same, the simulation does return values into the workspace variable.
Am I missing something? Is there any function to "refresh" the simulation without using the pause function? My actual code require small-to-zero delay, so using the pause function is not an option.
(see code+model attached)

Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!