Guide me in the figure

In a recent post, I was explaining in details how the M-file is organized when you used GUIDE (Graphical User Interface Development Environment)  to make interfaces. If you have used the GUIDE, you know that any program will be made of a M-file and a FIG-file. But what exactly is this Figure file?

Figure files are also used to save standard plot figure. It is a generic way to store data that is being displayed. If you have used Matlab for a while, you know that there are 3 types of files that Matlab likes to generate : M-file, MAT-file and FIG-file.

M-file is storing your code in text form. MAT-file is storing your arrays or data in binary form but what about FIG-file?

If you open any FIG-file with a text editor, you should get something like this :

MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Thu Apr 19 17:06:33 2012 flIMWxúÏY_hEü\“4mMHÑ(µÑä4ÅPR)V§rõ&çâò66iK· ŒÌÕ›MnogôôMü|V—S_Ñ”¯T…_ ˛AAäT©¯á RJÇÔ*:≥;≥∑;π$wõ4m°Ÿ|˜ÕŒ˜Ì˜˝ÊÔ7”∏˘ ÌÇwà’B⁄£‰ñÿ≥_<“ÙÏ–â!A∫^8†fiü_Ùê2QÜn¡ èQév;ä\Q <dcË5∫ƒÛ<®˘—V«èv≈%u+πàK>EÎı€7âC“>U|{YRπ∑1t‹=JˇŒªò3£)(“éóéá–x熆

In other words, you get a header and some binary encoded stuff. But then, a FIG file is just a MAT file! So quickly rename your FIG file by changing the extension to MAT and try to load it in Matlab….

Oh surprise, now Matlab sees a structure called ‘hgS_070000’ stored in this very same file.

Let’s load our renamed file and see what’s in this structure.

>> hgS_070000 =

type: ‘figure’
handle: 1
properties: [1×1 struct]
children: [1×1 struct]
special: []

So it seems that this structure is very well organized. Here you see that the handle to the figure is stored with 1 as value. I created this figure using figure(1), so it makes sense.

>> hgS_070000.children

ans =

type: ‘axes’
handle: 181.0023
properties: [1×1 struct]
children: [1×1 struct]
special: [4×1 double]

Now, one of the figure child is an ‘axes’. Again, this was an image so its parent was an axes, so it makes sense again.

You got the idea. Everything related to the figure is stored there. But then, we should be able to access to the raw data displayed on the axes, no? Indeed it should be in one of the children. This figure was an image as shown here :

>> hgS_070000.children.children

ans =

type: ‘image’
handle: 177.0043
properties: [1×1 struct]
children: []
special: []

It turned out that, as expected, the raw data is stored at :

This can come very handy if you have lost the original raw data on a figure file and want a convenient way to get it back!

Also knowing the way things are saved is always useful.

Now, coming back to our figure created by the guide. In the same way, the structure contain all the callbacks and their associated tag names as well as all properties to define the positions, color, etc of all objects on the interface.

This entry was posted in Intermediate, Making interfaces. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.