Programmatically duplicate signal in Simulink

조회 수: 25 (최근 30일)
David Mittiga
David Mittiga 2020년 9월 17일
답변: Scott Tatum 2022년 3월 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에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by