How to create a running window inside simulink model in MATLAB/Simulink that can take some sample of input data at every 0.05 sec time instance & feed to the MATLAB program ?
3 views (last 30 days)
I have simulated a model in MATLAB/Simulink, in which there is a MATLAB fcn block (MATLAB fcn block is available in simulink library browser, you can check it) inside which there is a program code, which accepts input data and converts it into its respective output, according to the code logic. Here while running the simulation from 0 sec to 5 sec, the matlab program code inside the Matlab fcn block, continuously accepts the input data and gives the output, according to the code logic. But, I want that the matlab code should take some samples of input data every 0.05 sec instance and converts it into the respective output. In the next 0.05 sec time instance, the matlab code will take next samples of input data and convert it into the respective output (thus creating a running window at every 0.05 sec time instance), and in this way the process goes on till the simulation time is over (from 0 sec to 5 sec). What is the code syntax to be added, in the existing program, so that the above can be achieved ?
I just want some suggestions, I am not asking for an exact answer ?
Fangjun Jiang on 8 Jun 2022
This is the fundermental basic of the Simulink simulation.
If nothing is constrained, set the solver to be discete, with fixed step size of 0.05, then everything (including the MATLAB Function block) is calculated (executed) at every 0.05 second. It takes 100 steps to finish the 0 to 5 second simulation.
If the solver and stepsize have to be something else, then put the MATLAB Function block inside a triggered subsystme, Use a Function Call Generator block to trig the subsystem, set the "sample time" of the Function Call Generator to be 0.5. Then the MATLAB Function block is executed every 0.05 second.