Change vector size in Simulink
7 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Ryan G
on 28 Nov 2012
Edited: Ryan G
on 28 Nov 2012
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.
More Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!