Programmatically connect SimScape blocks
12 次查看(过去 30 天)
显示 更早的评论
I am connecting simscape blocks programatically.
add_block('fl_lib/Electrical/Electrical Elements/Resistor','mymodel/Res1');
set_param('mymodel/Res1','position',[140,80+40,180,120+40]);
add_block('fl_lib/Electrical/Electrical Elements/Capacitor','mymodel/Cap1');
set_param('mymodel/Cap1','position',[220,80+80,260,120+80]);
set_param('mymodel/Cap1','Orientation','down');
add_line('mymodel','Res1/Rconn 1','Cap1/Lconn 1');
add_block('fl_lib/Electrical/Electrical Elements/Electrical Reference','mymodel/Ref1');
set_param('mymodel/Ref1','position',[220,80+160,260,120+160]);
add_line('mymodel','Cap1/Rconn 1','Ref1/Lconn 1');
% set_param('mymodel/Ref1','Orientation','down');
add_block('fl_lib/Electrical/Electrical Elements/Resistor','mymodel/Res2');
set_param('mymodel/Res2','position',[220,120,180,160]);
add_line('mymodel','Res1/Rconn 1','Res2/Lconn 1');
by changing the value of the position of the Res2 I am having the issue:
set_param('mymodel/Res2','position',[220,120,180,160]);
> In new_model (line 12)
Error using new_model
Invalid setting in Resistor block (mask) 'Res2' for parameter 'Position'
Caused by:
Error using new_model
Invalid definition of rectangle. Width and height should be positive.
Can you advice what can be an issue?
How can I connect the Res2 to the Wire instead of connectting directly to the output of Res1?
How can I amke the graph wiring stright, aligned programatically?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1314275/image.jpeg)
0 个评论
回答(1 个)
J Chen
2023-3-15
set_param('mymodel/Res2','position',[220,120,180,160])
is wrong. The third number (180) needs to be greater than the first number (220). The command needs to be something like
set_param('mymodel/Res2','position',[280,120,320,160]);
Adjust the parameters for the y-coordinate will made the wiring straight. For example
set_param('mymodel/Res1','position',[140,85+40,180,125+40]);
set_param('mymodel/Res2','position',[280,125,320,165]);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Electrical Sensors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!