- a string
- a valid model location
- unique (irrelevant if you set 'MakeNameUnique' to 'on')
Add_block command using with different destination
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hakan Yeniay
el 11 de Nov. de 2019
Respondida: Nick Morgan
el 21 de Jul. de 2020
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 comentarios
Respuesta aceptada
Nick Morgan
el 21 de Jul. de 2020
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!