Programmatically duplicate signal in Simulink

38 visualizaciones (últimos 30 días)
David Mittiga
David Mittiga el 17 de Sept. de 2020
Respondida: Scott Tatum el 30 de Mzo. de 2022
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!

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 17 de Sept. de 2020
add_line('SubSysBlock','InportBlock/1','MuxBlock/1','autorouting','on')
loop N times
  3 comentarios
Walter Roberson
Walter Roberson el 17 de Sept. de 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 el 18 de Sept. de 2020
Editada: Walter Roberson el 18 de Sept. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Scott Tatum
Scott Tatum el 30 de Mzo. de 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

Categorías

Más información sobre Schedule Model Components en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by