Is the MATLAB gui creator GUIDE as awful as I think? Is there an alternative?

wherestheforce picture wherestheforce · Oct 8, 2011 · Viewed 10.8k times · Source

I've been trying to put together a gui in MATLAB and have had great difficulty. Here is a little background about my program: I want to create a wizard to step users through an image analysis process. The wizard will cue users for their input and then perform an image processing action once a button labeled "Next" has been pressed, and so on. From reading the MATLAB help I believe there are two approaches to gui creation: 1. write a gui with lines of code. 2. use GUIDE.

I figured GUIDE would have the shallowest learning curve. At first the process was straight-forward. I could drag and drop buttons and text boxes and arrange them easily. My plan was to arrange a series of panels, with the buttons and text and etc., that would sequentially become visible as the "Next" button was pressed. And it was here I became stumped.

Once I save a panel with GUIDE, MATLAB creates a .m file and a .fig file. Reading through the .m file I see it has left room for me to write code for the callbacks, but little else. The .fig file is binary and therefore I dare not bother edit it. I am left wondering how I can control the objects, e.g. How to set the visibility of a panel? Furthermore, I had to create each panel of the wizard separately. I was hoping that I could manually combine the .m files into a wizard.m wrapper file, but I do not think this is the right approach (at least for me, because I cannot see how to do it).

In lieu of using GUIDE I've seen examples where guis are created using the "uicontrol" function. This approach seems tedious to me, because I would have to manually code the position and size and defaults of each button. Perhaps this is the best approach, but it intimidates me.

As a result I am unhappy with MATLAB for its seemingly clunky gui tools and I am unhappy with myself for lacking the chops to overcome this hurdle.

I've seen some fancy guis created in MATLAB and having attempted this myself and falling way short I am baffled by their existence. Either whoever made them were exceptional MATLAB users (I am not), or I am missing something obvious and could use some help seeing. I am now questioning whether a gui is worth the effort. I do not see myself exploring something like QT, because of the additional challenge of embedding MATLAB code into other languages such as python.

Does anyone have advice on this subject? Can anyone please point out where I am going wrong or why I am having such difficulty?

Answer

Mikhail picture Mikhail · Oct 9, 2011

The .fig file is binary and therefore I dare not bother edit it.

FIG file is a MAT file containing list of gui elements with properties you set in GUIDE.

How to set the visibility of a panel?

Assign a Tag to the element, you can access it using handles.mytag like set(handles.mypanel, 'visible', 'off')

Furthermore, I had to create each panel of the wizard separately. I was hoping that I could manually combine the .m files into a wizard.m wrapper file, but I do not think this is the right approach (at least for me, because I cannot see how to do it).

You can not combine these automatically generated m-files into one, why would you want to anyway? Keep a .fig and .m file for each wizard page!

In lieu of using GUIDE I've seen examples where guis are created using the "uicontrol" function. This approach seems tedious to me, because I would have to manually code the position and size and defaults of each button. Perhaps this is the best approach, but it intimidates me.

Using uicontrol directly is not bad if you do not position elements manually but use a layout manager. You can see some here and here. If you want you GUI to be nicely resizable then layout manager is the only way to do it.

Does anyone have advice on this subject? Can anyone please point out where I am going wrong or why I am having such difficulty?

Professional GUI programming is not easy, IMO is even the most difficult part at all.

Besides MATLAB GUI I have used both Java Swing and .NET WPF a lot, IMO MATLAB GUI is much easier, you can do 90% with 10% (learning) effort Sure, you still need time to become accustomed to it.

As a result I am unhappy with MATLAB for its seemingly clunky gui tools and I am unhappy with myself for lacking the chops to overcome this hurdle.

Yes, GUIDE is not the best solution but is probably the best technique to quickly create an GUI.

I've seen some fancy guis created in MATLAB and having attempted this myself and falling way short I am baffled by their existence.

These GUI's are hacks exploiting MATLAB GUI particular details like visual separator being a long '__________' black text on a white uicontrol which is only two pixel high or different colors in tooltip by using html.

And after all you can use Java Swing in a MATLAB GUI (because it is actually derived from Swing)

I am now questioning whether a gui is worth the effort.

Yes, in your case keep it very simple, just the functionality, do not think about fancy stuff!