Code covered by the BSD License  

Highlights from
choose_transect_limits

image thumbnail
from choose_transect_limits by Kevin Bartlett
GUI for choosing time limits of oceanographic transects

gpf(h)
function [parentFig] = gpf(h)
%
% gpf.m--Gets the parent figure of the object with handle h.
%
% Syntax: parentFig = gpf(h)
%
% e.g.,   figure; panelHndl = uipanel; 
%         pushHndl = uicontrol('style','push','string','Button',...
%                              'parent',panelHndl);
%         get(pushHndl,'parent') % parent is the panel, not the figure
%         parentFig = gpf(pushHndl)

% Developed in Matlab 7.2.0.294 (R2006a) on GLNX86.
% Kevin Bartlett (kpb@uvic.ca), 2006-11-24 16:25
%-------------------------------------------------------------------------

if isempty(h)
    parentFig = [];
    return;
end % if

if ~ishandle(h)
    error([mfilename '.m--Input argument is a non-handle object.']);
end % if

if h == 0
    error([mfilename '.m--Input argument is the root workspace.']);
end % if

handleType = get(h,'type');

if strcmp(handleType,'figure')
    error([mfilename '.m--Figures have no parent figure.']);
end % if

currHndl = h;

while 1
    
    currParent = get(currHndl,'parent');
    
    % This should never happen, but avoid any chance of an infinite loop by
    % testing.
    if isempty(currParent)
        error([mfilename '.m--Unknown error.']);
    end % if
    
    currParentType = get(currParent,'type');
    
    if strcmp(currParentType,'figure')
        parentFig = currParent;
        break;
    end % if
    
    currHndl = currParent;
    
end % while

Contact us at files@mathworks.com