Build MATLAB GUIs Programmatcially: an Introduction to Layout Toolbox

Two ways of building MATLAB GUIs

I never liked building MATLAB GUI with GUIDE(graphical user interface design environment) that comes out of box with MATLAB. It’s supposed to provide a easier, interactive way to build GUI and automatically generates the MATLAB code for constructing the UI. But the problem is, like other codes that are generated automatically, be it HTML script generated from Dreamweaver or C code from JAVA, the code is just not elegant, not to mention that UI features are limited.

What’s more, it require two files to define a usable GUI: one guiName.fig file representing the UI and one guiName.m file defining the under-hood behavour of your software. And the name of these two files must be the same. The normal ‘duplicate and change file name’ trick will not work on GUI built with GUIDE: even if you change both the file names to the same one, say ‘guiName2.fig’ and ‘guiName2.m’, it still won’t work. You need to go the GUIDE editor and click the “save as” button to create a copy.


Building a GUI programmatically, on the other hand, gives you full control of design style and features. You can add whatever text windows, push buttons, panels and plots. In stead of using as GUIDE requires, you only need one script to fully define a GUI. Those graphic objects will be generated once you run your code. You can also unleash the more advanced features like ‘uitree’ function group which is not available from GUIDE.

It’s nevertheless without pains. You need to build a UI from scratch. Position and size of each UI element have to be specified. Calculations of positions can be extremely painful especially at the early stage of design and constant revisions are needed. Fortunately, with the powerful GUI Layout Toolbox, we don’t have to do all these dirty work by ourselves.

GUI Layout Toolbox

Developed by David Sampson and Ben Tordoff from the Consulting Services group at MathWorks, this toolbox provides tools to create sophisticated MATLAB graphical user interfaces that resize gracefully. It fits perfectly with built-in MATLAB UI component. In addition, it allows drag-and-drop style of component rearrangement and comes with a highly-requested tab component.

It comes with a well-written concise documentation loaded with examples. The Getting Started section gives you a quick idea of using this toolbox, while the detailed Function Reference Pages will be your best friend if you are going to produce complicated GUIs.

This post tries to demonstrate some of the impressive features of this toolbox. Detailed GUI building techniques with Layout Toolbox will be posted in later series.

  1. Responsive and dragable window

2. Grid Layout


Like what you read? Give Hong Yu a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.