Get code from a GUI created using GUIDE

조회 수: 14 (최근 30일)
Juan
Juan 2014년 3월 26일
댓글: uopdon 2015년 2월 5일
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