Borrar filtros
Borrar filtros

How to create variable length buffer in Simulink for holding the value with unknown dimensions ?

5 visualizaciones (últimos 30 días)
i want to store a value of one signal in Simulink until the my trigger becomes high. Every time when trigger becomes high, the number of values of signal between two triggers are different.
i tried to use the following approach in MATLAB function block but it didn't worked
function = func(trigger , SignalA)
persistent store;
if isempty(store)
store=[];
end
if(trigger ==0)
store= [store SignalA];
end
end
it gives me following error
Assigning empty arrays to persistent variables is not supported.
Any other method to do this thing?
  1 comentario
Dyuman Joshi
Dyuman Joshi el 7 de Nov. de 2023
Editada: Dyuman Joshi el 7 de Nov. de 2023
The variable store is empty at the moment you are checking for the same.
Why reassign it?
It's redundant. Remove the if condition block.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Abr. de 2024
You are going to have trouble with that approach unless you use dynamic memory allocation.
Better is to set a maximum length between triggers, and use something more like
function buffer = func(trigger, SignalA )
Buffer_Length = 20480;
persistent store counter
if isempty(store)
counter = 0;
store = zeros(1, Buffer_Length);
end
if trigger == 0
if counter <= Buffer_Length
counter = counter + 1;
store(1, counter) = SignalA;
else
%do nothing, drop the sample
end
buffer = [];
else
buffer = store(1:counter);
counter = 0;
store = zeros(1, Buffer_Length);
end
end
As long as trigger is 0, this records the signal; if the recording would be too long then it drops the samples.
As soon as the trigger becomes non-zero, it releases all of the stored samples in one go, and resets the buffer.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by