필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
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
Dyuman Joshi
Dyuman Joshi 2023년 11월 7일
편집: Dyuman Joshi 2023년 11월 7일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 4월 27일
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.

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by