Simulink - Programmatically Set Vector Sizes at Run Time

I'm trying to run a model where the length of the vector (N_lag) changes each time I run "sim test2.slx".
for i = 1:M;
N_lag = N_lag + 1;
sim test2.slx;
end
Simulink gives me this after I accept its suggestion to name the vector (y) as a variable size vector with size [N_lag,1].
"Simulink cannot propagate the variable-size mode from the output port 1 of 'test2/Add' to the input port 1 of 'test2/Memory'. This input port expects a fixed-size mode. The variable-size mode originates from 'test2/MATLAB Function'. Examine the configurations of 'test2/Memory' for one of the following scenarios: 1) the block does not support variable-size signals; 2) the block supports variable-size signals but needs to be configured for them."
The problem is, I can't seem to find any type of block that will let me do this (global variable data stores also can't have variable size data). I'm trying to run the model a few thousand times, so hard coding the length of the vector is not an option.
The simplified block diagram is shown below.
Suggestions?
Thanks!
Capture.PNG

 採用された回答

Peter Grenfell
Peter Grenfell 2019 年 3 月 16 日

0 投票

I think I hacked a solution for those who are also interested in this. I basically allocated a fixed length, maximum memory vector (length N_max) for the memory block and a variable length vector for the data processing. Then I glued them together using converter functions that simply write/read 1:N_lag entries of the memory vector, leaving the rest of them alone so that the memory block only sees a fixed length data stream. Seems to work pretty well so far.
Capture.PNG

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Model Editing についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by