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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by