Why does the "Export" option in GUIDE make a script that doesn't work?

10 views (last 30 days)
I'm making a GUI in GUIDE. I thought the "Export..." option would give me a script I could run to create the GUI without needing the .fig file, but the script it generates has errors and does not run.
My GUI is called guiFig. When I work with it in GUIDE, I have the files guiFig.m and guiFig.fig. guiFig.m is a script that has callbacks, opening functions, and create functions, etc. When I use the "File>Export..." option in GUIDE to generate a file called guiFig_export.m, it generates a script that looks very similar at the top (same callbacks, etc) but also contains a function called guiFig_export_LayoutFcn that seems to be causing problems.
When I run guiFig_export, I get the following error message:
Error using uicontrol
While setting property 'Parent' of class 'UIControl':
Value must be a handle
Error in guiFig_export>guiFig_export_LayoutFcn (line 1049)
h14 = uicontrol(...
Error in guiFig_export>gui_mainfcn (line 1630)
gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
Error in guiFig_export (line 42)
gui_mainfcn(gui_State, varargin{:});
Here is the part of guiFig_export where h14 is defined, plus the bit before it where its parent is defined in case that is relevant:
appdata = [];
appdata.lastValidTag = 'uibuttongroup1';
h13 = uitools.uibuttongroup(...
'Parent',h1,...
'FontUnits','points',...
'Units','characters',...
'Title','M1 channels',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'Tag','uibuttongroup1',...
'Position',[8 17.6923076923077 33.6666666666667 11.8461538461538]);
appdata = [];
appdata.lastValidTag = 'array1';
h14 = uicontrol(... % THIS IS LINE 1049 WHERE THE ERROR IS
'Parent',h13,...
'FontUnits',get(0,'defaultuicontrolFontUnits'),...
'Units','characters',...
'String','1:32',...
'Style','radiobutton',...
'Value',1,...
'Position',[3 7.92307692307692 13.5 1.30769230769231],...
'Children',[],...
'Tag','array1',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
In the Editor, h14 is underlined and Matlab tells me that this value of h14 may be unused. There are several other handles with the same warning. If I comment out all the handles that have this warning, the script runs without errors, but a lot of the things on my GUI are missing.
Why is this specific handle causing an error (why are h1-h13 ok?)? Is there something I did wrong in GUIDE that caused the exported script to have errors?
  2 Comments
Rik
Rik on 16 Jul 2018
These kinds of errors are why for a long time I believed GUIs are really difficult stuff. It turns out it's just GUIDE making your life difficult.
Going on-topic: Are there other elements that have a buttongroup as their Parent? That may be the problem here.
For radios I just use the Callback function to set the others to false, which removes the need for this structure, although it means you'll have to edit all Callbacks if you add or remove a radio, which is non-ideal.
You could get around that by creating a group yourself (saving it in guidata), using set to turn all Value parameters to 0, then doing set(hObject,'Value',1). For my uses that was too much bother, but for you it may be worth it.
Kate Derosier
Kate Derosier on 16 Jul 2018
Yes, I tried to put 3 radio buttons and a text box inside a buttongroup. The behavior I want is for there to be radio buttons for Option A, Option B, and Other, and then a textbox for the user to enter the value for other.
I'm a little confused by your suggestions for fixing it. You're saying that the problem is that GUIDE isn't generating the code to set other options to 0 correctly?

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!