using add_block in a for loop
2 次查看(过去 30 天)
显示 更早的评论
Hello, my problem is about creating Simulink Model in with script, due to variable model size I want to generate my model with help of for loops. When I use such command:
for k=1:n
Submodulename =sprintf('Submodule_%d' ,k);
pos = [x y+3*k*offset (x+w) (y+h+6*k*offset)];
add_block('NPC_MMC_Library/Submodule', Submodulename,...
'Position',pos);
end
Even my variable block name Submodulename is changing but add_block doesn't work,
thanx for any help in advance, Regards
2 个评论
采纳的回答
C.J. Harris
2014-12-3
编辑:C.J. Harris
2014-12-3
I see you have defined a source block ('NPC_MMC_Library/Submodule'), however your destination doesn't appear to include the model name you are adding it to. I would expect your source to be of the format ['my_model/', Submodulename].
The reason it is failing is you are trying to add a block without stating which model you are adding it to.
Try this:
for k=1:n
Submodulename =sprintf('Submodule_%d' ,k);
pos = [x y+3*k*offset (x+w) (y+h+6*k*offset)];
add_block('NPC_MMC_Library/Submodule', ['my_model/', Submodulename], ...
'Position',pos);
end
Note: Replace 'my_model' with the name of your Simulink model
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Configure and View Diagnostics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!