Programmatically duplicate signal in Simulink

43 views (last 30 days)
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!

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 17 Sep 2020
add_line('SubSysBlock','InportBlock/1','MuxBlock/1','autorouting','on')
loop N times
  3 Comments
Walter Roberson
Walter Roberson on 17 Sep 2020
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 on 18 Sep 2020
Edited: Walter Roberson on 18 Sep 2020
@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.

Sign in to comment.

More Answers (1)

Scott Tatum
Scott Tatum on 30 Mar 2022
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

Categories

Find more on Schedule Model Components in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!