How to send one array element at a time to a subsystem every 0.5 seconds in Simulink?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ben Navon
am 14 Apr. 2025
Kommentiert: Mathieu NOE
am 16 Apr. 2025
Hi all, I'm working on a Simulink model where a MATLAB Function block outputs an array of control commands (the command array is generated once at the start of simulation). I’d like to send one command at a time from this array to a subsystem input, with a rate of 2 Hz (i.e., one value every 0.5 seconds).
What’s the best way to implement this?
Thanks in advance!
3 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 14 Apr. 2025
Nothing special. Use a Counter block (free-running or limited) in combination with the model solver setting to provide the step (every 0.5 second). Feed it to this function.
function y = fcn(u)
persistent cmd
N=10;
if isempty(cmd)
cmd=zeros(N,1);
end
if u==0
cmd=10*(1:N);
y=0;
elseif u>=N
y=cmd(N);
else
y=cmd(u);
end
end
2 Kommentare
Fangjun Jiang
am 16 Apr. 2025
Feed the Counter block to the MATLAB Function block input.
The function output is the "one array element at a time".
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Event Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

