Code covered by the BSD License  

Highlights from
choose_profile_limits

image thumbnail
from choose_profile_limits by Kevin Bartlett
Allows user to choose limits of oceanographic profile (e.g., CTD cast)

cpl_finish_box_drag(thisLineTag)
function [] = cpl_finish_box_drag(thisLineTag)
%
% cpl_finish_box_drag.m--Callback to be invoked when one of the box lines
% is dragged and released.
%
% Syntax: cpl_finish_box_drag(thisLineTag)

% Developed in Matlab 7.0.1.24704 (R14) Service Pack 1 on GLNX86.
% Kevin Bartlett (kpb@uvic.ca), 2006-03-21 10:57
%-------------------------------------------------------------------------

thisLine = findobj(gcbf,'Tag',thisLineTag);
%cpl_constants = get(gcbo,'userdata');
cpl_properties = getappdata(gcbo,'cpl_properties');

set(gcbo,'WindowButtonUpFcn','');

% Use the line's tag to find out if it is from a start box or an end box.
START = 0;
END = 1;

if strfind(thisLineTag,'startBox')
   boxType = START;
else
   boxType = END;   
end % if

% Do not allow a box to be dragged beyond the plot limits.
%thisLineXVal = unique(get(thisLine,'xdata'));
currPt = get(gca,'CurrentPoint');
xVal = currPt(1,1);

xlims = get(findobj(gcbf,'Tag','full_ax'),'xlim');

if xVal < min(xlims)
   xVal = min(xlims);
end % if
   
if xVal > max(xlims)
   xVal = max(xlims);
end % if

% Find out how far the drag point is from the corresponding crop line.
if boxType == START
   cropLine = findobj(gcbf,'Tag','full_ax_StartLine');
else
   cropLine = findobj(gcbf,'Tag','full_ax_EndLine');
end % if

cropX = unique(get(cropLine,'xdata'));
boxWidth = 2*abs(xVal - cropX);
boxWidthPct = (boxWidth/range(xlims))*100;
cpl_properties.boxWidthPct = boxWidthPct;
%set(gcbo,'userdata',cpl_constants);   
setappdata(gcbo,'cpl_properties',cpl_properties);

cpl_update(gcbo);

Contact us at files@mathworks.com