File Exchange

image thumbnail

Convert FIG to MATLAB code

version 1.1 (8.54 KB) by

Generate programmatic GUI MATLAB File from a FIG-File

4.3913
26 Ratings

13 Downloads

Updated

View License

FIG2M - Generate programmatic GUI M-File from a FIG-File

Version : 1.0
Created : 10/05/2006
Modified: 14/04/2010
Author : Thomas Montagnon (The MathWorks France)

>> outputFile = fig2m(guiName,outputDir,syscolorfig,cb_gen);

guiName -> Name of the Fig-File (absolute or relative path)
outputDir -> Directory where the generated M-File will be saved
syscolorfig -> Use system default background color (true or false)
cb_gen -> Generate callbacks (true or false)
outputFile -> Name of the generated M-File

>> fig2m

If you call the function with no input arguments it will ask you for the parameters.

Comments and Ratings (36)

Eduardo Toma

For the people with the following error:
Error in ==> fig2m at 430
disp(listTemp.Tag);
Change the line 88 from: [guiPath,guiName,guiExt] = fileparts(guiName);
to: [guiPath,guiName,guiExt] = fileparts([pwd '\' guiName]);
And it works perfectly.
Thanks Olivier for this contribution!

Roman Gorlov

@ Omar Ashour: This seems to be a bug in the code. You can fix it by adding these two lines under the first nested if-statement on line 333:
str = sprintf('%s\t\t\t''%s'', %s, ...\n',str,propTemp{indProp},propVal);
continue;
This will not try to parse propVal incase of a Parent or UIContextMenu.

Jan Keller

Jan Keller

Jan Keller

Omar Ashour

In R2016a, all the 'parent' properties are set to 'on' or 'off' instead of a handle. Any way around that besides fixing them manually?

Just perfect!!!

Remy Billoire

I got the same error by simply testing 2D plot

Error in ==> fig2m at 430
disp(listTemp.Tag);

Manoj Kiran

Simply awesome. This guy is great.

MSleiman

Error in ==> fig2m at 430
disp(listTemp.Tag);

Why are we getting this error?
Is it solvable?

Sergei

Sergei (view profile)

Martin

Martin (view profile)

The line 430 error appears during the error handling.
*fig2m turns the .fig file name into a function and calls it; in other words, the .fig must be in the same directory as its accompanying .m caller.
*Object properties change over time. If fig2m reports "Reference to non-existent field", say, EraseMode, comment out that field.
*The above were enough to generate the _build.m file, which was pretty decently formed. Depending on the quality of the .fig file, there may be bad references to handles. or handles.1, generally non-critical components which can be renamed or cut.

Khanh

Khanh (view profile)

Hi,

Could someone can convert and show successfully a figure with uitable? The table isn't show with cell except the border of it.

If anyone has solution, please post it. Thanks

Khanh

Khanh (view profile)

Great job. Can't image without your wonderful program.
Thank you so much.

francesco

hi,
when I run the fucntion it ends up with an error, how solve it?

Error in ==> fig2m at 430
disp(listTemp.Tag);

Martha

Martha (view profile)

fig2m worked perfectly for me in R2012a. @shikhar, when I first ran the code, I encountered the error you describe; the problem seemed to be in setting the GUI directory. If you run the code with no inputs, it prompts you to select the path and .fig file, which allows it to run to completion without error.

shikhar

tried to run it but i got the following error:

Error in fig2m (line 430)
disp(listTemp.Tag);

i tried it with 3 different matlab versions and currently i am using matlab R2012b but the same error appears in every case ...how did you make it run ? please reply....

shikhar

tried to run it but i got the following error:

Error in fig2m (line 430)
disp(listTemp.Tag);

i tried it with 3 different matlab versions and currently i am using matlab R2012b but the same error appears in every case ...how did you make it run ? please reply....

shikhar

tried to run it but got the following error:

Error in fig2m (line 430)
disp(listTemp.Tag);

i tried it with 3 different matlab versions and currently i am using matlab R2012b but the same error appears in every case ...how did you make it run ? please reply....

Amihay Blau

Great program!
helps when working with multiple Matlab versions, when creating more than one form in a GUI and a lot more.

thanks

Urs Schuerch

Beautiful, many thanks.

Otis

Otis (view profile)

Good work!! Did just what I needed!!

Robert W.

same problem as martin.

Dion

Dion (view profile)

This is a great tool and it's surprising that something similar has not been implemented within Matlab.

Martin1986

Okay, i think i get the Problem, but iam not sure why, it works for guis which have no input/output o.O so my maingui works but the guis which get called from the main doesn't work

Martin1986

maybe iam to stupid but if i let it run i get always the error message
??? Undefined function or variable "listTemp".

Error in ==> fig2m at 430
disp(listTemp.Tag);

if i comment this i become multiple error msg
fig2m
Index exceeds matrix dimensions.

fig2m
Reference to non-existent field 'samplerate3'.
i use i with M2009b i whould be happy if someone have an idea...

Ian

Ian (view profile)

This has converted a number of Guide GUIs into more managable M files without trouble for me. The only thing missing is parsing the callbacks into the new M file.

Jonathan Lister

This worked really well. I had a very complicated custom plotting tool that I developed in 2009a. My tool worked well until I tried to run it on an older version (7.1 2005b0-ish). The fig file binary must have changed between those versions. This tool has helped me start to work around that issue. Thanks!

I have a suggestion:
Although my custom toolbar and the push and toggle buttons were translated perfectly, the tool did not preserve their order. I would like to see your tool do that in the future, as well as copy over all of the callback and other functions in the original m-file.

Wow, nice work.

qooroo

qooroo (view profile)

really really nicely done.

Thierry Dalon

Great! Well done.

Nicolas MONTAGNON

Great job Brother !

vaibhav Waghmare

I wish to have updated copy of the same utility. Can you please mail me.

Thanks

vaibhav Waghmare

Thanks Thomas,
This is a really very nice utility b'coz, GUIDE helps us to develop a gui and gives basic m file which does not have programming details. m file developed by this function is really excellent and can help us to modify the properties of image

Thanks

Zhijun Wang

Very good work!

Updates

1.1

- Change the function name from generate_m_file to fig2m
- Bug corrected for generation of String property value containing new line and ' characters.
- Add support for uitoolbar, uipushtool and uitoggletool
- Add support for uitable controls

MATLAB Release
MATLAB 7.3 (R2006b)
Acknowledgements

Inspired: Graphical Points Selection, img2curve

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video