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

1 次查看(过去 30 天)
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?

回答(1 个)

Nathan Hardenberg
Nathan Hardenberg 2023-7-17
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:

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by