Programmatically duplicate signal in Simulink

47 次查看(过去 30 天)
Hello,
I cannot seem to find a simple way to programmatically replicate a signal into a vector in Simulink. For example, I'd like to create a trivial subsystem which has a single inport and outport which is configured only by a single parameter: N. The subsystem would have a single mux inside (with N inputs) and the inport would connect to all mux inputs. The below screenshot represents what I am referring to for the case of N=8. The only thing I can't seem to figure out is how to programmatically connect the inport to all N mux inputs. Can someone please assist?
Thanks!

采纳的回答

Fangjun Jiang
Fangjun Jiang 2020-9-17
add_line('SubSysBlock','InportBlock/1','MuxBlock/1','autorouting','on')
loop N times
  3 个评论
Walter Roberson
Walter Roberson 2020-9-17
When I was digging a few months ago, I could not figure out how Simulink represents connections between components.
All I could find was that line objects were represented as a list of coordinates, and that if you added a line with a list of coordinates that started at one component and ended at another component, then the components were considered to be connected (I verified this in the sense that I wrote code that was able to connect components by generating coordinates and using them.)
The approach of figuring out whether a particular line happened to overlap an outport of something and an inport of something else just doesn't seem sustainable -- for example if you resize a component or move it, then the previous coordinates should no longer work, but Simulink appears to find all the affected lines and update them. It seemed pretty fragile and high overhead for something that occurs so often.
Fangjun Jiang
Fangjun Jiang 2020-9-18
编辑:Walter Roberson 2020-9-18
@Walter,
  1. The line object does have other properties such as 'SourcePort', 'DstPortHandle', etc.
  2. The list of coordinates is needed as it describes the shape/form of the line, plus, a line could have no source or destination.
  3. When the user draws a line manually, the line is deemed connected when the end point is in the approximation of the destination port. I think this is the reason for the behavior you described.
  4. It is certainly more convenient to connect through port, although connecting through points could also be useful such as this one below.

请先登录,再进行评论。

更多回答(1 个)

Scott Tatum
Scott Tatum 2022-3-30
insert a gain witht the value of ones(N,1)
h_gain = add_block('simulink/Math Operations/Gain','myModel/repgain','Gain',sprintf('ones(%d,1)',N));
% connect lines
add_line('myModel','In1/1','repgain/1') % input line
add_line('myModel','repgain/1','Out1/1') % output line

类别

Help CenterFile Exchange 中查找有关 Schedule Model Components 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by