What does the slreportge​n.utils.co​mpileModel function actually do to a model?

5 vues (au cours des 30 derniers jours)
Mohammad Rifat Arefin
Mohammad Rifat Arefin le 2 Avr 2022
Modifié(e) : Vaibhav le 17 Nov 2023
What does the slreportgen.utils.compileModel(modelname) function actually do to a model? If I try to close the the compiled model without uncompiling it first, the following error is shown. What does the uncompile function do here?
load_system('sample.mdl')
slreportgen.utils.compileModel('sample.mdl')
%slreportgen.utils.uncompileModel('sample.mdl') works with this line
close_system('sample.mdl')
Error using close_system
Cannot close the model 'sample' when it is being compiled or while the simulation is running
On the other hand, I can successfully close the system after the sim function.
sim('sample.mdl')
close_system('sample.mdl')
What is the reason behind this behavior?

Réponses (1)

Vaibhav
Vaibhav le 17 Nov 2023
Modifié(e) : Vaibhav le 17 Nov 2023
Hi Mohammad
I understand that you would like to know the background working of "slreportgen.utils.compileModel(modelname)", "slreportgen.utils.uncompileModel(modelname)" and "sim(modelname)" functions.
The "slreportgen.utils.compileModel(modelname)" function takes the model name (modelname) as an argument and compiles the specified model. Once compiled, the model is loaded into memory, ready for simulation or code generation.
Uncompiling a Simulink model unloads the compiled model from memory. This frees up system resources and allows you to close the model without any issues. When you attempt to close a compiled model using "close_system('sample.mdl')" without first uncompiling it, the error is encountered, this is because the model is still loaded into memory.
To close a compiled model without errors, first uncompile it using "slreportgen.utils.uncompileModel('sample.mdl')." This frees up the system resources associated with the compiled model and allows to close it properly. When using the "sim('sample.mdl')" function to simulate a model, it automatically uncompiles the model after the simulation is complete. This behavior ensures that the compiled model is unloaded from memory only after the simulation has finished using it.
You can refer to the following MathWorks documentation links to know more about "slreportgen.utils.compileModel", "slreportgen.utils.uncompileModel" and "sim" functions respectively.
Hope this helps!

Catégories

En savoir plus sur Configure and View Diagnostics dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by