MATLAB: How to save the model automatically in Simulink before building it
simulink coder
I would like to automatically save my Simulink model and then generate code form it using Simulink Coder.
Best Answer
In the attached example, you can find how to implement this behavior in the OpenFcn Callback in Block Properties of a subsystem with the following script:
save_system(gcs);
rtwbuild(gcs);
If you double click the subsystem, it will save and then build the model.
You could also create a customization to the Simulink User Interface, by adding a new item to the Code Menu with a custom Build action. If you add the attached sl_customization.m to your MATLAB path and run "sl_refresh_customizations", it will add this new item to the Code menu and it can be started with Ctrl+Shift+B.
The ability to create a package including a Simulink model and all of the libraries referenced by that model is not available in Simulink.
To work around this issue, use the SLDIAGNOSTICS command with the 'Libs' option to return a list of the libraries referenced by a model, and then manually include the appropriate libraries.
The "restoredefaultpath" function restores search path to its factory-installed state. To refresh function and file system path caches please use “rehash” function and "_sl_refresh_customizations_"
>> rehash toolbox
>> rehash toolboxcache
>> sl_refresh_customizations
sl_refresh_customizations Refreshes Simulink menu and dialog customizations.
Best Answer