Clear Filters
Clear Filters

How to perform a block opeartion at particular time index in simulink?

1 view (last 30 days)
I want to find optimum value ofa parameter at each time index. For that i want to perform 2500 iterations for every time index in simulink simulation. For eg. when the simulation starts and T=1 sec, this matlab function block will perform 2500 iterations and find optimal value for this particular T. Now, T=2 sec, matlab function block will again perform 2500 to find optmal value of parameter particularly for T=2 sec and so on.
How can I execute this in simulink?

Answers (1)

Nathan Hardenberg
Nathan Hardenberg on 17 Jul 2023
Check out the "Enabled Subsystem". Put your MATLAB function in there and only enable it on your desired timesteps.
One way to do this is with another MATLAB function, that could look like the one below. The input t would be the output of a "Clock"-Block.
function y = fcn(t)
if t == 1.00 % one second
y = 1;
elseif t == 2.00 % two seconds
y = 1;
else
y = 0; % do not execute subsystem
end
end
If you do it like that please use a "Fixed-step" and an appropriate "fundamental sample time" so every desired timestep gets executed as a Simulation step. To have millisecond precision for example, use:

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!