File Exchange

image thumbnail

Auto Layout Tool

version 2.3 (2.58 MB) by McSCert
The Auto Layout Tool is used to automatically improve the layout of Simulink models.


Updated 22 Jul 2020

From GitHub

View Version History

View license on GitHub

Modeling operations often perturb a model's layout. Layout readjustment is usually needed, and represents a tedious activity if performed manually. Although achieving a proper layout of a Simulink model is deemed very important, there does not exist a comprehensive commercial automatic layout tool for Simulink models. The Auto Layout Tool resizes models' blocks based on number of inputs and outputs, and organizes the signal lines such that the number of crossings is minimized. Auto Layout Tool can leverage three different layout approaches: 1) "Graphviz", a third-party open source tool for drawing graphs; 2) Matlab’s built-in "GraphPlot" layout capability; 3) an in-house "DepthBased" method. Approaches 1) and 3) can be utilized on any version of Matlab/Simulink, while approach 2) only works on R2015b+.

• For installation instructions and instructions on how to use the tool, see Auto-Layout/doc/AutoLayout_UserGuide.pdf.

• This tool relies on our Simulink Utility. Please download it here:

For more about the capabilities of the tool and how it can be used in model-based development with Simulink, see the following two papers:

[1] Vera Pantelic, Steven Postma, Mark Lawford, Alexandre Korobkine, Bennett Mackenzie, Jeff Ong, Marc Bender, "A Toolset for Simulink: Improving Software Engineering Practices in Development with Simulink," In Proceedings of 3rd International Conference on Model-Driven Engineering and Software Development (MODELSWARD 2015), SCITEPRESS, 2015, 50-61. DOI: (Best Paper Award)

[2] Vera Pantelic, Steven Postma, Mark Lawford, Monika Jaskolka, Bennett Mackenzie, Alexandre Korobkine, Marc Bender, Jeff Ong, Gordon Marks, Alan Wassyng, “Software engineering practices and Simulink: bridging the gap,” International Journal on Software Tools for Technology Transfer (STTT), 2017, 95–117. DOI:

Cite As

McSCert (2021). Auto Layout Tool (, GitHub. Retrieved .

Comments and Ratings (33)


@Damien Grilliere: All of our tools rely on our "Simulink Utility" submodule, which can be downloaded here: Please make sure it is on your Matlab path. Unfortunately, GitHub submodules are not automatically included in the .zip download from the File Exchange, nor GitHub. This is a limitation of GitHub. You will notice that your Auto-Layout/src/Utility folder is empty, which is where the submodule files should be. If you are using git, you can download all of the needed files at once using the command: "git clone --recursive". Sorry for the inconvenience.


It's ok sorry for the spam !
I have to download the Simulink-Module made in McSCert ;)
Thx for your work !


when I launch the following command > AutoLayoutSys(gcs)
An error appears > Undefined function or variable 'inputToNumeric'
Could you help me please ?
Why convert the system name in numerical value ?


@Sebastian Grau: All our tools are now available on GitHub here: AutoLayout is here:


@michael: The earliest version of Matlab that we tested was R2011b. If you are using with any version earlier than R2015b, the Graphing Method (as detailed in Section 2.1.1 of the user guide) needs to use the third "GraphViz" layout approach (recommended) or the second "in-house" layout.


@Sebastian Grau: Yes, we have plans to put our tools on GitHub, but currently do not have an set date when this will be complete by.

Sebastian Grau

Do you plan on putting your tool on GitHub in order to enable others to contribute?


Is there a chance to use the tool for older Matlab / Simulink versions (for example R14SP3)?


@Gran Ray C. Marabi: Try running "which AutoLayout". If that gives the message "'AutoLayout' not found.", then the tool needs to be added to the MATLAB search path.

Once AutoLayout is on the path, run "sl_refresh_customizations" and then try right-clicking in a Simulink model. You should see the Auto Layout option.

If that still doesn't work, try restarting MATLAB and ensure AutoLayout is still on the path. This should not be necessary after running "sl_refresh_customizations", but is worth trying.

We will update the user guide to ensure that these steps are more clear. If you are still having an issue, please send the error message and model to Thanks!

Gran Ray C. Marabi

I have added the 'C:\ProgramFiles(x86)\Graphviz2.38\bin' in the system path but still the 'Auto Layout' in the Context menu is still unavailable.
I am using MATLAB R2017a version.
Please assist.

Here is what I have done.
1. Define the 'C:\ProgramFiles(x86)\Graphviz2.38\bin' in the system path.
2. Moved the AutoLayout folder to 'C:\Users\*\Documents\MATLAB'.
3. Opened the AutoLayoutDemo.mdl

Is there any steps I have missed?

Thank you very much!


@sibabalo noludwwe: The AutoLayoutSys function requires a system name or handle as input. You may be experiencing issues if your "system" variable is empty. Please ensure that your model is open, and then try running: AutoLayoutSys(gcs)

sibabalo noludwwe

I tried running the AutoLayoutSys with the example attached but I am getting the error below:
Not enough input arguments.

Error in AutoLayoutSys (line 11)
systems = inputToNumeric(systems);
please assist

Hadi Zyien

Super useful!

Jerki Jokne


Mark Lawford


@Dana Parsavand: Thank you for reporting your issue with the tool. We think we know what the problem might be, but would like to confirm it by reproducing the error. To that end, would you be able to tell us what versions of Graphviz and Matlab you are running the tool on?

Dara Parsavand

I installed Graphviz installed on my Windows 7 PC and have updated Windows and Matlab paths. However, I can't get the example (AutoLayoutDemo) to work. When I right click in the model and select Auto Layout, I error out. I used the debugger to see that I make it to the file TplainParser.m, line 63 just before the error. I see filename = 'AutoLayoutDemo-plain.txt' which must not exist because the next line (tline = fgetl(inputfile);) errors out. I must be missing something, but the PDF userguide is pretty short and I don't see any steps I didn't do.

I'm very keen to see how well this works compared to SysGen's routine because we are mostly using straight Simulink these days and don't want to depend on having to install SysGen to get their autolayout function. I wonder when Mathworks will include this functionality which seems pretty important.

Mikhail Sedelnikov


@Honigmelone: Thank you for the feedback. We are interested in looking at your model, if you can share it with us, so that we can work on addressing this issue. You can e-mail us at


Good idea, unfortunately it does not really perform well with flipped blocks for me (such as in feedback loops).



@Ganesh Hegade: The newest version of the tool (1.4) should address the issue you are encountering. Thanks again for your feedback.


@Ganesh Hegade: We will look into ways of fixing this issue. Thank you for bringing it to our attention!

Ganesh Hegade

This is a pretty nice tool to perform AutoLayout of Simulink system. Thanks a lot for providing this tool.
I am using this tool from sometime and i found below bug.

In my work I created a Matlab GUI and added an option to create Simulink diagram from GUI. After the creation of Diagram i was trying to call AutoLayout to rearrange the blocks. But while rearranging blocks, Auto Layout Tool is closing the GUI itself and then throwing the error saying the model is not found.

Investigation / Possible reason :
I tried to debug the error and found that the error is inside the functions getTextHeight and getTextSize. Here you are using command "uicontrol", and then closing the parent of the figure using "close(get(x, 'parent'));". But if you have a Matlab GUI open, then by default Matlab GUI will become parent(as GUI is a figure) and the close command closes the GUI and all other things. Hence the error.

Work Around:
As a work around I am creating a new figure before assigning the "uicontrol" and making that as parent. This workaround looks as below:
function height = getTextHeight(string, block)
newFig = figure;
x=uicontrol('Style', 'text', 'FontName', fontName, 'FontSize', fontSize);
set(x, 'String', string);
height=get(x, 'extent');
close(get(x, 'parent'));
Same solution for getTextSize also.

Can you please check is there any better workaround or solution can be added for this in upcoming releases.



@Torsten Knodt: Thank you for checking out our tool. We are interested in looking at your model, if you are able to share it with us. You can e-mail us at

Torsten Knodt

nice to see the submission of such a tool here.

I have tried your toolbox on a relatively small SimPowerSystems model with a relatively "chaotic" result. For the case you are interested, I can provide you the model or pre-post screenshot and dot file to e.g. an email address of your choice.



@Rami: Thanks for bringing this to our attention. This error seems fairly non-specific, so we are going to ask a couple questions to see if we can understand better what occurred.

1) What's size of the model in terms of number of blocks?

2) What are your naming conventions on blocks? Anything with spaces and/or newlines? We've had issues with that before.

3) Does the tool attempt to move any blocks or change the model in any way before the error occurs?

4) In the directory where you saved the Auto Layout Tool, is there a .dot file that was generated from the model?

This should give us a better idea of when the error was produced.

Thanks, Bennett and Gordon


I get the following error when trying to apply on a complicated system with subsystems and feedback loops.

"Error using dotfile_creator (line 149)
Invalid Simulink object handle

Error in initLayout (line 40)
[filename, map]=dotfile_creator(address);

Error in AutoLayout (line 32)

Error in AutoLayoutGUI>pushbutton1_Callback (line 85)

Error in gui_mainfcn (line 96)

Error in AutoLayoutGUI (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in

Error while evaluating uicontrol Callback"

I tried out the examples and they work. Please responed and help me out.


Great idea! I will test and give you feedback. Please continue supporting it


@William Knox: Thank you for the feedback! From what we can tell based on your situation, you are working on a very large scale system. Presumably with the scale at which you're working at, when the Auto Layout Tool tried to space things out for legibility's sake it exceeded the hard limits of MATLAB's position coordinates, and threw an error when it tried to move a block past said point. This is something we can definitely consider, and we're glad it's been brought to our attention.

To best address this concern, would it be possible for you to give us the .dot file produced when the error was thrown? When the program completes its execution successfully, normally it gets rid of the file as part of cleanup. However, since yours cut out before it could finish, we would imagine the file was still there, in the directory where you saved the Auto Layout Tool toolbox (most likely, this is under MATLAB/Toolboxes/Auto Layout Tool). Thanks, Bennett and Gordon

William Knox

G'day developers,

I successfully installed and tested example model in Matlab 2014a (via System Generator 2014.3).

Tried to run on a subsystem with
-522 'Inport' blocks,
-522 Xilinx SYSGEN 'Up Sample' blocks,
-an 'm-code' block with 522 input ports and 52 output ports, lastly
- the 'm-code' block has terminated outputs i.e. all output ports are connected to 'Terminator' blocks (for testing).

The position of the 'm-code' block is [870 165 1165 21165].

An excerpt of the errors produced is provided below (between ---> and <---):
Error: Edge length 286957.000000 larger than maximum 65535 allowed.
Check for overwide node(s).
many more of the type of errors shown above ... and below --->
Error: Edge length 175524.000000 larger than maximum 65535 allowed.
Check for overwide node(s).
Error using TplainParser/go_to_the_right_spot (line 105)
Input bounds are out of range

Error in TplainParser/plain_wrappers (line 45)
go_to_the_right_spot(object, object.RootSystemName,mapObj, graphinfo);

Error in AutoLayout (line 46)

Error in AutoLayoutGUI>pushbutton2_Callback (line 95)

Error in gui_mainfcn (line 95)

Error in AutoLayoutGUI (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)AutoLayoutGUI('pushbutton2_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

I appreciate that this model/subsystem may not be a typical model/subsystem and that the 'Auto Layout Tool' was probably not designed for such models/subsystems.

This submission is not so much a request for help but more a feedback (for a possible bug fix).

Thank you for your time.

Kind regards,


MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!