How to store data poins in Simulink from a GoTo to use it in the same simulation?

1 visualización (últimos 30 días)
Hi,
I need a list of values generated from a simulation, with these values I want to do a linear interpolation. The problem is that when I implemet the matlab function in Simulink I see that the values that the function is reading are single values and not a vector/array/list wich is what I need.
Any Idea on how to do that?

Respuesta aceptada

Hari
Hari el 15 de Sept. de 2023
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.
  1. 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.
  2. 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)
% x: Input buffer containing N values
% y: Interpolated output values
% Perform linear interpolation
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.

Más respuestas (0)

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by