Get code from a GUI created using GUIDE

25 次查看(过去 30 天)
I created a GUI using GUIDE a while ago. Now I have realized that a few things I want to do would be easier if had created the GUI form scratch using the editor. Instead of starting over again I would like to use what I already have. Is it posible to get the code that creates all the objects in the GUI that I set up with GUIDE? (I have the m files that GUIDE creates, but I can't find where the buttons, checkbox, etc are set). Thanks
  2 个评论
per isakson
per isakson 2014-3-27
" that a few things I want to do would be easier" Some examples of these things would help
uopdon
uopdon 2015-2-5
I fully understand Juan's point. I also prefer the programmatic approach to creating GUI's, but find it slightly difficult to sketch out where the objects go, which is where GUIDE could come in handy. I want to use GUIDE to sketch out the GUI, and then simply get the programmatic code that would generate the same GUI. I would also like to be able to use the property inspector in GUIDE to edit properties - for example I find it a lot easier (and more creative) to set the background colour of a control using GUIDE. However, I then want GUIDE to create the programmatic version of the code with the non default value attributes.

请先登录,再进行评论。

回答(3 个)

Image Analyst
Image Analyst 2014-3-26
Not sure I follow. You can create a new GUI with GUIDE then view any callback to get the new, empty m-file. Then you can copy and paste from some other, old m-file into the new one, if you want to.

Joseph Cheng
Joseph Cheng 2014-3-26
The only way I can think of getting the positions and parameters from the GUI items would be to insert a section within the startup to grab the desired parameters for each and save them to a file.
example:
%insert into yourGUI_OpeningFcn(hObject.....
pushbuttonAttribute = get(handles.pushbutton1);
Then you'll have to save or record these for your use.
  6 个评论
Image Analyst
Image Analyst 2014-3-26
Not that I know of. Why do you want to go through such pain and inconvenience anyway?
Joseph Cheng
Joseph Cheng 2014-3-27
编辑:Joseph Cheng 2014-3-27
There is anotherway... Still painful but not that bad, probably can make this in like 20 min (including debuggin). Since each ui-object is saved within handles.
  1. save handles using save('handles.mat','-struct','handles')
  2. exit existing gui and clear all variables.
  3. load handles.mat
  4. listofuiobjects = who;
  5. fid = fopen('textfile.txt')
  6. write for loop to get(listofuiobjects(i).Position) and style and other param.
  • uitext = [''uicontrol('Style',' retreivedStyle ','Units','pixels','Position', ' retreivedPosition ' ,'Enable','off'))'] %this is air coding (saw term in another post here and liked it-similar to air guitar) so don't hold it against me if the string concatenation is wrong.
6. fprintf uitext within the above forloop.

请先登录,再进行评论。


per isakson
per isakson 2014-3-26
编辑:per isakson 2014-3-27
" Is it possible to get the code that creates all the objects in the GUI that I set up with GUIDE?"
I think it is possible to create a function, fig2mfile, which takes the "figure" as input and outputs an mfile function, which in turn can create the figure.
The figure is a rooted tree of handle graphic objects. Starting with h=findall(fig_h,1,'-depth',1) and get(h(ii)) it is possible to to build that tree as a structure. Next it's possible to traverse the tree and create all the graphic handle objects, which would result in a huge mfile of set(handle,name,value). There is nothing of this kind in the File Exchange - as far as I can see.
The fig-file of GUIDE is a mat-file (behaves like a mat-file if you change the extension to .mat), which contains a huge structure. The structure is easy to navigate.
.
However, for practical purposes it is NOT possible.
  • And one day The Mathworks will present next generation of GUI building tools.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by