MATLAB Answers

per isakson

Automatic tool to generate Sequence and Class Diagrams (UML)

Asked by per isakson
on 6 Feb 2012
Latest activity Commented on by per isakson
on 14 Oct 2016

Answer 2 on 2012-03-10:

Answer 2 on 2012-03-07: I replaced the diagram. The possibilities to control the layout are limited. How much control is needed?

Answer 2 on 2012-02-29: What characteristics of a UML sketching and documentation tool are required to make it useful in the design and programming process?

Answer 1 on 2012-02-24: I have started to make a tool.

Question on 2012-02-12: Does it exist a tool to automatically generate UML-diagrams from Matlab m-code? If not I plan to make a simple tool.


I want an automatic tool to generate UML diagrams from MATLAB code. Thus, I ask for your comments on the following idea. Is is worth to try? Is there already such a tool for MATLAB? There are for other languages.

Currently, I sporadically use the interactive tool UMLet, which is really easy to use. However, I don't update the diagrams when I make changes to my MATLAB-code.

The idea is to put together a tool that consists of three parts

  • A home made MATLAB-code that reads MATLAB class definition files and writes code in a simple domain specific language, DSL, for PlantUML
  • PlantUML converts the DSL-code to a GraphViz dot-file
  • GraphViz produces the diagrams

I have looked at the three open source tools, TextUML, UMLGraph and PlantUML. I have experimented a bit with PlantUML and picked that.

I hope to get something working in a short time. However, there is a tool, PlantUML Dependency, which creates code for PlantUML from Java-code. It's many lines of code!

There are a number of contributions in the File Exchange. I'll study them.

Here is a list of the tools that I've found.

Maybe, The Mathworks has a tool that can be contributed to the File Exchange. However, I assume that this UML Class Diagram is not generated automatically.


Thank you for asking. I have a little tool, m2uml, which I use on a regular basis.

  • m2uml automatically creates PlantUML code for "partial" Class Diagrams. The boxes are complete with properties, methods and visibility indicators. m2uml handles inheritance and packages well enough. However, m2uml does neither handle multiple superclasses nor mixins. And more important it does not handle associations automatiaclly.
  • m2uml reads information from the Matlab meta.class object
  • I gave up on both retrieving information from the code of classdef files and adding PlantUML code fragments to Matlab comments.
  • The dependencies between classes are an important part of a class diagram. I define the associations in a PlantUML script, which I give as input to m2uml.
  • m2uml asks for a GUI, but I cannot envision the details. The real problem is more about my work flow. All my "class diagrams" are test cases of my unit testing tool.
  • Currently I use copy&paste to PlantUML Server and has neither PlantUML nor GraphViz installed on my computer.

I don't think it worth trying to do anything automatically with Sequence Diagrams. The info needed is provided by my function, trace4m. However, in real world cases the diagram explodes in size. The text output is good enough for understanding how existing code behaves.

I use PlantUML to make some sequence diagrams to support design decisions.

I'm positive that using some simple UML-diagrams helps make better Matlab programs as argued by Martin Fowler, UmlAsSketch

Hi Per, thank you for posting your thoughts and plan of action! I agree with you 100%, Matlab definitely needs a UML tool so that users can benefit from proper visualization of O-O designs.

Would you mind please updating us on your progress over the last year? Thank you in advance, and good luck with the project :)

It took long, but now I've uploaded m2uml

2 Answers

Answer by per isakson
on 24 Feb 2012

I've done some experiments with PlantUML+Graphviz. My Matlab tool automatically generates PlantUML-code based on the m-files. This class diagram is based on the classes, which are provided in the FEX-contribution "Class Inheritance Browser". (I can use some advise on including pictures.)

UML diagrams can include a lot of detail. How much detail is useful? How do I extract the needed information from the Matlab-code? I know of meta.class.fromname, profile('info'), evalc( 'mlint( ''-calls'', filespec )' ); and my tracer4m.

Is it a good idea to write "UML-code" in the comments of the m-files for this tool to read? Is there a "language" that I could borrow from? (V) in the diagram stands for value-class.

UML-diagrams for real programs easily becomes so huge and cluttered that they are useless. Would it be a good idea to include "UML-code" in comments of the m-files, based om which it is possible to filter the diagram, e.g conditionally exclude unimportant classes?

I need help to make a useful tool and FEX-contribution!


The Taxi class has two sets of properties and methods. I have to find out why!

And inherits twice from Car

I defined the class Taxi twice.

Answer by per isakson
on 29 Feb 2012

2010-03-07: I replaced the diagram. (S) stands for Singleton.


I incude a Class Diagram that I just generated automatically. It shows some classes from an experiment I did last year. The red square in ICE_waitbar indicates that it is a singleton; the constructor is private. The last thing I did was to suppress displaying of inherited properties and methods. (H) stands for inheritance from the handle class. I don't want a separate box for the handle class.     

The associations between State and IceProxy looks a bit strange. (I cannot do much to the crossing arrows!)

Now, I'm need to think about the requirements. What would be useful and what not. Goals:

  • The diagram shall provide overview. 
  • Little effort and little distraction; m2uml must not disturb the workflow 
  • Simple and cheap (require little time) to use 
  • Include m-functions in the class diagram.  

Would it be a good idea to include "significant comments" in the comments of the Matlab source code? That is to say short strings preceded by some special character, e.g. "¤". For example, I thought about the codes "¤L1", "¤L2" and "¤L3" (level 1,2 and 3) to use a bit like outline view in Ms Word. A class at level, L3, would not be included in an overview. From there it is easy to envision a set of keywords forming a kind of language. Multiplicity might be specified with a "significant comment"



Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!