User`s guide
15 Examples of GUIs Created Programmatically
Pass Output to a Caller on Returning
If a host GUI calls the colorPalette function with an output argument, i t
returns a function handle that the host GUI can call to get the currently
selected color.
The host GUI calls
colorPalette only once. The call creates the color palette
in the specified parent and then returns the function handle. The host GUI
can call the returned function at any time before the color p alette is destroyed.
The data definition se ction of the
colorPalette code file creates a cell array
to hold the output:
mOutputArgs = {}; % Variable for storing output when GUI returns
Just before returning, colorPalette assigns the function handle,
mgetSelectedColor, to the cell array mOutputArgs and then assigns
mOutputArgs to varargout to return the arguments.
mOutputArgs{} = @getSelectedColor;
if nargout>0
[varargout{1:nargout}] = mOutputAr gs{:};
end
Share Data Between Two GUIs
The Icon Editor example G UI, described next, embeds the colorPalette GUI to
enable the user to sele ct colors for the ico n cells. T he colorPalette returns a
function handle to the iconEditor. The iconEditor can then call the returned
function at any time to get the selected color. The following two sections
describe how the two GUIs work together.
The colorPalette GUI. The
colorPalette function defines a cell array,
mOutputArgs, to hold its output arguments.
mOutputArgs = {}; % Variable for storing output when GUI returns
15-60