Add_block command using with different destination

조회 수: 6 (최근 30일)
Hakan Yeniay
Hakan Yeniay 2019년 11월 11일
답변: Nick Morgan 2020년 7월 21일
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

채택된 답변

Nick Morgan
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:
  • a string
  • a valid model location
  • unique (irrelevant if you set 'MakeNameUnique' to 'on')
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개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by