- a string
- a valid model location
- unique (irrelevant if you set 'MakeNameUnique' to 'on')
Add_block command using with different destination
6 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am trying to add simulink block to my model with add_block command. But I have a lot of subsytems and my destination name always change.
"place" is the string variable which is give destination
'Test/1ms/Diag' or it is change according to subsytem 'Test/1ms/Diag1' ....
Matlab gives error when I use this command
temp=add_block('simulink/Sinks/Scope',place ,'MakeNameUnique','on', 'Signal',get(srchandle,'SignalName'));
Invalid destination block specification
How can I use add_block with different destinations
0 件のコメント
採用された回答
Nick Morgan
2020 年 7 月 21 日
Hi Hakan,
You should be able to use add_block with different destinations as long as your 'place' variable is:
You can try setting your 'place' variable as a row vector to increase the flexibility of your program and to make it easier to use changing destinations. See the code below for an example of this.
for a = 1:4
% place variable as a changing row vector
place = [sys '/System1/C' num2str(a)];
pos = [x,y+offset*a,x+w,y+h+offset*a];
add_block('built-in/Constant',place,'position',pos);
end
The For Loop changes the 'place' variable every loop making it easy to use different destinations.
The full code is below if you would like to run it and see the results.
function newModel(sys)
if nargin == 0
sys = 'new_model';
end
open_system(new_system(sys));
x = 30;
y = 30;
w = 30;
h = 30;
offset = 60;
% place variable as a set string
place = 'new_model/System1';
pos = [x,y,x+w,y+h];
add_block('built-in/Subsystem',place,'position',pos);
for a = 1:4
% place variable as a changing row vector
place = [sys '/System1/C' num2str(a)];
pos = [x,y+offset*a,x+w,y+h+offset*a];
add_block('built-in/Constant',place,'position',pos);
end
Nick
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Programmatic Model Editing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!