![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/515572/image.png)
Simulink Programmatic Modeling - Large quantity of blocks
5 views (last 30 days)
Show older comments
Regards,
I have written a script to create a Simulink model via MATLAB lines of code systematically. Said script is scalable to increase the number of blocks to model a discretized physical problem with Simscape Multibody. The code works correctly and has been tested for small numbers of blocks. However, the amount of computational time to create the Simulink model is relatively high. Currently, I have a script that should make a Simulink model with a little over 2000 blocks. This script has been running for seven days now. MATLAB has not crashed or stopped, and according to the Windows task manager, it consumes 45GB of RAM and a moderate amount of processor resources.
At this point, I ask myself the following:
a) How to know if the model is still being created or just MATLAB has failed and should be stopped?
b) is there a limit to the number of blocks within a Simulink model?
I appreciate any helpful advice or information on what decision to make.
0 Comments
Answers (1)
Jonas
on 10 Feb 2021
Edited: Jonas
on 10 Feb 2021
I have never programatically created a Simulink model, so I admire you for doing that, but cannot help with the specific functions you are calling to perform your task.
I suggest adding flags to your script to get feedback on the process of your script. You can use disp() to print to the Command Window during your loops, such as the index. You can also use sprintf() for example.
I don't know if there is a practical limit to the number of Simulink blocks, but 2000 is surely not too many. I am currently working on a model with a multitude of blocks.
If it is indeed so that MATLAB is struggling with creating many blocks, you may opt for creating smaller submodels, and then putting those submodels as a Model Reference in a larger model as a final step. This way, not all blocks are to be created in one large model.
You could also run your script for creating a smaller model, and run the Code Profiler. This way you can identify the sections of code which take long to execute and try to fix it. You do this by clicking this button in the editor:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/515572/image.png)
Of course, it only displays the final report after the code has finished executing. So you should run it when your script is generating the small model and actually finishes. You could then run it again, when you increase the model a bit to see how your code scales with the size of the model you generate.
0 Comments
See Also
Categories
Find more on Simscape Multibody in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!