Hi Santiago,
I understand that you have a simulation in SIMULINK, and you need to perform linear interpolation on a set of values generated by the simulation. However, when using the Function block, you noticed that it reads the values one by one instead of as a vector/array/list.
To address your need, you can use the “Buffer” block in SIMULINK to collect the values and then perform the interpolation on the collected data. Here's an approach you can follow:
In your Simulink model, place a Buffer block after the simulation block or the block that generates the values you want to interpolate.
- Configure the Buffer block to store the desired number of values. Set the "Output buffer size" parameter to your desired value based on the number of values you want to interpolate.
- Connect the output of the simulation block or the block generating the values to the input of the Buffer block. Place a MATLAB Function block after the Buffer block to perform the linear interpolation. For example, if you have a buffer of size N and want to interpolate the N values, you can define input and output ports as follows:
function y = linearInterpolation(x)
y = interp1(1:numel(x), x, 1:numel(x), 'linear');
By using the Buffer block to collect the values and then performing the linear interpolation using the MATLAB Function block, you can interpolate the collected values simultaneously.
Refer to the documentation of “Buffer” block in SIMULINK for more information.
Refer to the documentation of “interp1” function in MATLAB for more information.
Thanks,
Hari.