Building a Model Using Model Construction Commands
This section shows you how to use model construction commands to add blocks to your models and connect them.
Suppose you want to add a PI Section Line block and a Voltage Measurement block to your model, connect the + terminal of the Voltage Measurement block to the left end of the PI Section Line block, and connect the - terminal of the Voltage Measurement block to the right end of the PI Section Line block.
The following code shows you how to add and position the two blocks in your model.
add_block('powerlib/Elements/Pi Section Line','Mymodel/Block1'); add_block('powerlib/Measurements/Voltage Measurement', 'Mymodel/Block2'); set_param('Mymodel/Block1','position',[340,84,420,106]); set_param('Mymodel/Block2','position',[520,183,545,207]);
For each block you want to connect, you need to know the handles of the terminal ports.
Block1PortHandles = get_param('Mymodel/Block1','PortHandles'); Block2PortHandles = get_param('Mymodel/Block2','PortHandles');
add_line command uses the
variables to connect the blocks. The
represents the right connectors of the blocks and the
represents the left connectors. You then need to specify to the
the indices of the connectors you want to connect.
add_line('Mymodel',Block1PortHandles.LConn(1), Block2PortHandles.LConn(1)); add_line('Mymodel',Block1PortHandles.RConn(1), Block2PortHandles.LConn(2));