Change vector size in Simulink

5 ビュー (過去 30 日間)
Fabian
Fabian 2012 年 11 月 28 日
Hi,
A few times now, i encountered the situation that i want to change the size of an vector. Maybe i start with an example(see picture): http://www.bilder-upload.eu/show.php?file=bdbf1e-1354099408.png I have a mechanism that performs a certain action on every item in a vector. I have to use this a lot, so i made an generic library-subsystem from it. This bloc has an input for the vector and one for the number of relevant signals (to save calcualtion time). The Subsystem only accepts a vector with the size 10, but doesn't care about the lower 7 values in this case.
Now i have to use this bloc a lot with variing number of input signals. Is there a way to increase the size of a vector (here size 3) to match the input of the procesing bloc, without using a MUX everytime? The new lines in the vector can be filled with anything, as they will be ignored anyway.
Something like a bloc that has one input for the vector to be changed and one for for the new size (So either crop or expand it)
If you read this, thanks for you attention

採用された回答

Ryan G
Ryan G 2012 年 11 月 28 日
編集済み: Ryan G 2012 年 11 月 28 日
You can use a gain block utilizing matrix multiplication instead of element-wise that has a vector, such as:
[eye(3) zeros(7,3)' ]'
Depending on the dimensions. Essentially the eye(3) maintains the original inputs and the zeros pads the rest. For a 4 element vector it would look like:
[eye(4) zeros(6,4)' ]'
Hopefully this makes sense. I'm not sure if there is an easier way but there might be.
  1 件のコメント
Fabian
Fabian 2012 年 12 月 4 日
Thanks, works like a charm

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by