Simulink often needs to generate files to simulate a model. An example of this is the model reference simulation target. Today I will describe a few option to control where those files are created.
If you click play in the following model:
You will notice that a folder named slprj with a lot of code and 4 MEX-files will be created:
If you do not want the slprj and MEX-files to be generated in your current directory, it is possible to go in the Simulink Preferences and specify a Simulation Cache Folder and a Code Generation Folder to be used instead of the local directory.
Overriding the Simulink Preferences
Now, let's say I need to often switch between different projects, and each of those projects need to use different folders for code generation. In that case, it is possible to use Simulink.fileGenControl. For example, if I include Simulink Project in my workflow, the startup shortcut for my project could look like:
project = simulinkproject; projectRoot = project.RootFolder; myCacheFolder = fullfile(projectRoot, 'work'); myCodeFolder = fullfile(projectRoot, 'code'); Simulink.fileGenControl('set',... 'CacheFolder', myCacheFolder,... 'CodeGenFolder', myCodeFolder,... 'createDir', true)
That way, all the code and MEX-files generated by the model will go in those folders and the current directory will remain clean.
Once you are done working on this project, you can restore the values stored in the Simulink Preferences using this line:
Don't Clean Up: Faster Initialization
Simulink checks the cached files at initialization to make sure they are up to date and match the model. This prevents re-generating files, and results in faster initialization. If you regularly work with the same models, keeping these derived files around can help you save time when switching between projects.
Now it's your turn
Let us know how you use this feature by leaving a comment here
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.