matlabcode-generationsimulink

Is there a programmatic way to generate s-functions directly out of Simulink blocks


I would require wrapping the logic of my Simulink model to be obfuscated or hidden. One of the ways to perform it is to create a similar s-function block with the object code generated from the same Simulink block. I am facing difficulty in realizing this programmatically. Is there a way around to realize them programmatically or rely on GUI to create manually.


Solution

  • The workflow can be summarized as follows:

    Code generation settings:

    Once the above steps are done go ahead with building the model block programmatically:

    oldBlockPath=getfullname(gcbh);
    newBlockHandle=slbuild(gcbh) % gcbh points to handle of current selected block 
    newBlockPath=getfullname(newBlockHandle);
    pil_block_replace(oldBlockPath,newBlockPath);
    

    The above code snippet can implement the idea at a fundamental level for a selected block.

    Reference: MATLAB Answer's