diff --git a/Utility functions/findFigure.m b/Utility functions/findFigure.m index 398fd1f..6c48fae 100644 --- a/Utility functions/findFigure.m +++ b/Utility functions/findFigure.m @@ -1,34 +1,44 @@ % Find matlab.ui.Figure handle in structure or class instance function Fig = findFigure(Obj) % First check if the object itself is a figure if isa(Obj, 'matlab.ui.Figure') Fig = Obj; return end + % If the object contains 'Gui' property, search over it instead of the + % object itself. + gui_prop_name_list = {'gui', 'Gui', 'GUI'}; + ind = ismember(gui_prop_name_list, properties(Obj)); + if nnz(ind) == 1 + tag = gui_prop_name_list{ind}; + Fig = findFigure(Obj.(tag)); + return + end + % Find figure among the object properties if isstruct(Obj) prop_names = fieldnames(Obj); else if isvalid(Obj) prop_names = properties(Obj); else Fig = []; return end end % Try to find the figure among the properties figure_ind = cellfun(@(x) isa(Obj.(x),'matlab.ui.Figure'), prop_names); if any(figure_ind) % Returns the 1-st figure among those found fig_names = prop_names(figure_ind); Fig = Obj.(fig_names{1}); else Fig = []; end end