Seth on Simulink

June 19th, 2008

What’s in your model?

This morning I was telling my colleague Rob about the blog post I was writing on sample time colors. We talked about models that demonstrated the concept, and he dove into his computer to find an example he had made a couple years ago. I liked the model, so I asked him if he would send it to me, but here was a problem. The model was in a directory with about 50 other M-files, MAT-files and MDL files. How would Rob know which files to send me? Without much thought, Rob was able to identify the two files I would need to run that model. How did he do it?

Model Dependencies

A Simulink model is rarely just a single file. Simulink models often depend on the entire MATLAB environment to run. Most models rely on many more files run correctly. You may need MAT-files, M-files, reference models, S-functions, and C code to recreate the working environment. I have suffered through this repeatedly when working with models sent in to technical support. Many times, the models are missing just a couple files. We discover which file is missing and request it, only to find out there are additional dependencies. Most engineers have experienced this on some kind of development project and then resolve to keep their work more organized.

Model Manifest Tools

My colleague quickly identified his model dependencies using the model manifest tools in Simulink. In R2007a the model manifest tools were added. They provide a short cut method for analyzing your model to identify its dependencies, and then make it simple to package those files into a ZIP file. Take for example, this Lunar_Mission model (download) from the 2007 Simulink World Tour.

Lunar mission model
(Click here for Simulink WebView)

If I wanted to upload this to the File Exchange and share this with the Simulink Community, how would I do that? The documentation on model dependencies goes over this process step-by-step. Access the Tools->Model Dependencies->Generate Manifest… menu to generate the XML manifest file. The dialog presents you with some options to control the scope of your search for dependencies. I started by unchecking the items I did not want to include in the initial Simulink Manifest File (.smf).

Generate model manifest dialog

When you click Okay, it begins analyzing your model and produces an HTML report. Here is a snapshot of the output from the Lunar_Mission model.

Lunar Mission manifest report image
(Click here for the full dependency report, links in the report won’t work)

The final step to allow me to share this is to export the files in the manifest. I can package these files up in a ZIP file with just a couple clicks. This is another menu found at Tools->Model Dependencies->Export Files in Manifest…

Export manifest to a zip file

Maintaining a manifest for your Simulink project is extremely helpful. This enhances collaboration between people working on the same project. A manifest can also be included in a configuration management system as a way to record all the files needed to run.

Now it’s your turn

Do you collaborate in Simulink? How do you keep your models organized? Are there any naming conventions that help you? Post a comment here and tell me about it.

5 Responses to “What’s in your model?”

  1. Roger replied on :

    Good blog! However, I expected to find some information on the extremely annoying “Trouble solving algebraic problem” in Simulink. Can you please shed more light on this problem and various ways of tackling it.

    Thanks

  2. Gavin Walker replied on :

    The file dependency analysis that is used by the Simulink Manifest Tools can also be called programmatically: for Seth’s example, one could call

    >> files = dependencies.fileDependencyAnalysis(’Lunar_Mission’)

    from the MATLAB command line to get a cell-array of the files used by the model Lunar_Mission.

  3. Truong replied on :

    Hi Seth,

    I have a question that I hope you can help. As you know, we can ask Simulink to display the execution order of blocks using a menu option in the model window. However, I need to obtain the execution order from my Matlab code (in an m. file). Is there any way to do that? Any function? I believe there must be one but I couldn’t find it. Thanks!

  4. Mike Katz replied on :

    Truong,

    You can use command line debugger to get the sorted list:

    f14
    sldebug(bdroot)
    slist
    
  5. parth damani replied on :

    This was very helpful. I want one help about if you have any idea. I want to generate .mdl file from .m file, so that i can generate verilog code from .mdl file. Is it possible in matlab?

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Seth Popinchalk is an Application Engineer for The MathWorks. He writes here about Simulink and other MathWorks tools used in Model-Based Design.
  • Mohamamd: Hi Suth, I try to simulate a load tap-changing transformer in simulink but its control part has to be...
  • Han Geerligs: Hello Guy, thanks for the clarificaton and link. However in the documentation I am missing the...
  • Guy: @Han, you probably already know, but I think it is good to share with everyone. To zoom in use the key...
  • Han Geerligs: Hi Seth, Once again I’d like to point out that my biggest accelerator is using mouse and keyboard...
  • XaL: Hi, thanks for the tips. As someone wrote in http://blogs.mathwor ks.com/seth/2009/03/ 13/new-%C2%A0rele...
  • Uba osy: Hi, in the introductory example for fuzzy logic toolbox it was noted that using non fuzzy means, you could...
  • Prashant: How can I have same example but instead AC(1 to 10V 50 or 60Hz) and DC(0.5 to 10 V) then adding AC+DC but...
  • adrian chavarro: Great tool, for educational and sicentific, simulation. I would like to know where can i place a...
  • Ashish Sadanandan: @wei, I was talking about the case where the compiler would perform the ‘model_Xdim...
  • wei: @Ashish, I agree with your observation on compiler optimization but fail to see why Han’s code would be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.