Clear Filters
Clear Filters

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

22 views (last 30 days)
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.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 22 Apr 2013
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.

Products

Community Treasure Hunt

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

Start Hunting!