How to add Simulink Library Block programmatically ?

11 visualizzazioni (ultimi 30 giorni)
Hi,
I try to generate a Simulink model with using add_block() function programmatically. I have an issue with a block path. When I use following example everything is ok.
sys = 'testModel';
new_system(sys) % Create the model
open_system(sys) % Open the model
pos = [30 37 60 50 ];
add_block('simulink/Sinks/Scope',[sys '/In1'],'Position',pos);
But if I try to insert another blocks I get an error : There is no block named 'NI VeriStand Blocks/NIVeriStand In1'
sys = 'testModel';
new_system(sys) % Create the model
open_system(sys) % Open the model
pos = [30 37 60 50 ];
add_block('NI VeriStand Blocks/NIVeriStand In1',[sys '/In1'],'Position',pos);
I thought that the path is same like in Simulink Library Browser, but it’s wrong probably
Is there any way how to found the path to the Simulink blocks?
Thanks Jan

Risposta accettata

Sebastian Castro
Sebastian Castro il 25 Set 2015
Modificato: Sebastian Castro il 25 Set 2015
The name of the model is not the same as what shows up on the Library Browser. It just happens to be so for "Simulink", whose library file name is simulink.slx.
If you right-click the "NI VeriStand Blocks" library and select "Open NI VeriStand Blocks library", it will bring up the model file, which will tell you the actual name of the model. I can't tell you what that is since NI VeriStand is a third-party library and I don't have it.
Take this other one as an example. If you right-click your DSP System Toolbox library and open it in the above fashion, the model name (in R2015b) will be dsplibv4. Furthermore, when you click "Sources", it will open a new model called dspsrcsv4.
Bottom line: You can't tell the path of the block by looking at its user-visible name. Best thing to do is to
  1. Right-click the library and open it outside the Library Browser
  2. Navigate to, and select, the block you're interested in adding
  3. Enter gcb in MATLAB to get the exact block path you should use
- Sebastian

Più risposte (0)

Categorie

Scopri di più su Interactive Model Editing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by