フィルターのクリア

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

5 ビュー (過去 30 日間)
Adan91h
Adan91h 2018 年 7 月 9 日
回答済み: Walter Roberson 2024 年 4 月 27 日
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 Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by