Change vector size in Simulink
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!