- set the System Target as 'rtwsfcn.tlc',
- make sure "Create new model" is selected, and
- use the subsystem handle to call the 'rtwbuild' function like
How to generate a Simulink S-Function programmatically?
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander Gebel
am 17 Jul. 2017
Kommentiert: Moritz Burghardt
am 23 Sep. 2021
Hello, i have different Simulink models with lots of Subsystems in there. Some of these Subsystems must be generated as s-function. I was thinking about writing a script to generate the s-functions, but i don't found a function building s-functions programmatically. Is there any way?
0 Kommentare
Akzeptierte Antwort
Saurabh Gupta
am 19 Jul. 2017
You should be able to use a combination of instructions in the following two documentation sections to write a script that generates S-functions for you.
The high level idea is to
>> new_block = rtwbuild(subsystem_handle)
The 'rtwbuild' function will return the handle to the newly created S-function block, which you should be able to use to perform the intended operations on the new block (like replacing the sub-system with it or saving the block in a new model).
2 Kommentare
Gordon
am 24 Aug. 2017
If the subsystem is connected to a bus-signal, this method won't work:
"The input to the Bus Selector block must be a virtual or nonvirtual bus signal.A possible cause of this error is the use of a bus-capable block"
When manually clicking "Build selected Subsystem" Simulink automatically creates two subsystems left and right to the s-function. Is there any way to programmatically (via script) trigger this process?
Thanks very much in advance!
Moritz Burghardt
am 23 Sep. 2021
You need to deselect the option "Generate Code only". You can do it programatically:
set_param(cs,'GenCodeOnly',0); % Deselect "Generate code only"
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Block and Blockset Authoring finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!