MATLAB Answers

How to get simulink library and block names for the add_block function?

17 views (last 30 days)
Richard Crozier
Richard Crozier on 17 Sep 2012
Commented: pj110 on 24 Sep 2015
Hello,
I would like to create a Simulink model programatically, using commands such as add_block etc. However, I'm having trouble finding out the correct names for the libraries and blocks in the libraries. As a specific example I have tried to add a Level-2 M-File S-Function with a command similar to the following:
add_block('simulink/User-defined Functions/M-S-Function', 'mymodel/thesfunction')
This however gives the error:
??? There is no block named 'simulink/User-defined Functions/M-S-Function'
It's also not clear whether I have to first load the User-defined Functions library first in this case. So I'm not sure if I have got the name of the library wrong, or something else.
In general how do I find the correct library name and block name for adding the block to a model programatically?

  1 Comment

Richard Crozier
Richard Crozier on 17 Sep 2012
In fact even the following does not work for me
add_block('simulink/Sinks/Scope', 'mymodel/Scope')
Yielding:
??? There is no block named 'simulink/Sinks/Scope'

Sign in to comment.

Accepted Answer

Ryan G
Ryan G on 17 Sep 2012
I bet this is because the Simulink library is not loaded. Try doing this first:
load_system('simulink');

  5 Comments

Show 2 older comments
Richard Crozier
Richard Crozier on 17 Sep 2012
Thanks the following works (slight case diff)
add_block('simulink/User-Defined Functions/Level-2 M-file S-Function','mymodel/thesfunction')
Your general method for getting the right names is what I was looking for, thanks.
pj110
pj110 on 24 Sep 2015
I have the same problem but I want to add a '/Asynchronous Machine SI Units' but I get the error " There is no block named 'Simscape/SimPowerSystems/Second Generation/Machines/Asynchronous Machine SI Units' is this any way that I can use add_block() function for other toolboxes in simulink library such as Simscape and ...
Regards,
Pj
pj110
pj110 on 24 Sep 2015
Good news I found it. Bad news the gcb commands give different path and names for each component in SimPowerSystem but by finding the root library path you can add the name of the any of the components you get the block on your mdl or xls file.
for example gcb command for the selected component gave me below: powerlib/Machines/Simplified Synchronous Machine pu Units however it was not the Simplified Synchronous Machine pu Units so I write the firs to part of the path and then I added the name of the component that I want. whatever it works for me but the gcb command is not operate correctly by choosing the component from the library and typin gcb on command window it gives different names for that component. now I use add_block and use powerlib/machines and append the correct name for my component to get the desired block on my mdl file. it has worked for me. for other toolbox it seems the same problem.
pj

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!