I understand that you are trying to run an attitude determination algorithm for a satellite with the data collected from numerous sensors after every batch of ‘M’ samples collected.
You can achieve this task by utilizing, “MATLAB Function” and “Triggered Subsystem” block.
Firstly, you can implement the attitude determination algorithm which you want to perform after every batch in the “Triggered Subsystem” block and you can write a function inside a “MATLAB Function” block keeping the “data” variable in which all the data will be stored as “persistent” as it has to maintain its state over various function calls and updating it after each sample time.
You can use a Boolean variable “trigger” which is true only when you get a batch of ‘M’ samples.
Now you can connect the inputs from sensors to “MATLAB Function” block’s input ports and connect the “trigger” signal to the trigger port of the “Triggered Subsystem” and connect the “data” output from the “MATLAB Function” block to “Triggered Subsystem”.
Now as you know the size of the “data” signal will vary as time progresses, hence you must right click on the block, select explore and from model explorer click on data variable and check the “Variable size” box and mention the maximum size of the signal in the “size” field.
Here is a sample model for the same workflow where I am taking average of samples from a sine wave (Here the precision improves as the number of samples increases and average moves close to 0):
Code for the “MATLAB Function” block:
function [data,trigger,countval] = recursive_estimator(new_batch)
all_data = [all_data;new_batch'];
batch_size = batch_size-1;
Here is the model explorer for the “MATLAB Function” block:
After this setup, you can run the simulation to get the required results.
For more information, you can refer to the following documentation links:
- https://www.mathworks.com/help/releases/R2024b/simulink/slref/matlabfunction.html
- https://www.mathworks.com/help/releases/R2024b/simulink/ug/triggered-subsystems.html
I hope it helps!