How to initialize the size of a Simulink vector with a constant block

22 次查看(过去 30 天)
I have a nx1 length rand vector being used in a Simulink model. I would like to be able to change its length, n using a constant block. I am new to Simulink so this is probably a pretty basic question but I can't get it to work. I can create the vector as a constant with rand(10,1) for example or I can set N=10 in the Matlab workspace and use rand(N,1) as the constant but I want to be able to change N on the block diagram.

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2013-4-22
If 'N' changes during simulation, it essentially means that the size of the signal (Nx1) changes during simulation. These types of signals are called Variable-size signals in Simulink and must be bounded (ie. you need to specify an upper bound for N). I can't think of an existing block that lets you output a variable-size signal with values rand(N,1), but you can easily implement such a block using a MATLAB Function block. Please also remember to configure the block to output a variable-size signal.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by