for ii=1:length(marker_color)
col_ind = strfind(colors,marker_color(ii));
if ~isempty(col_ind) %It's a color
color = marker_color(ii);
else %Try a marker instead
mark_ind = strfind(markers,marker_color(ii));
if ~isempty(mark_ind)
marker = marker_color(ii);
end;
end;
end;
end;
%Handle default marker and color
if ~exist('color','var'), color = 'r'; end; %set default
if ~exist('marker','var'), marker = '*'; end; %set default
%Add the cursors.
%Ideally, the user specified the 2 x coordinates.
%If not, just put the cursors somewhere nice.
lineh = local_findlines(axh);
%Line data
if isempty(lineh)
x1 = 0;
y1 = 0;
% erasemode = 'normal'; %default
else
%if multiple lines, define callback to allow for selection
set(lineh,'ButtonDownFcn', ...
'setappdata(get(gco,''Parent''),''SelectedLine'',gco);dualcursor(''selectline'',[],[],[],get(gco,''Parent''))');
%set erasemode to xor. This speeds things up a ton with large data sets
% erasemode = get(lineh,'EraseMode');
% set(lineh,'EraseMode','xor');
lineh = min(lineh); %Lets just use one line. This was probably added first
setappdata(axh,'SelectedLine',lineh); %The currently selected line.
%Why the last line? Because it is the first one added
xl = get(lineh,'XData');
yl = get(lineh,'YData');
end;
%Find nearest value on the line
[xv1,yv1] = local_nearest(x_init(1),xl,yl);
[xv2,yv2] = local_nearest(x_init(2),xl,yl);
%Build the string for the data label
textstring1 = feval(datalabelformatfcnh,xv1,yv1);
textstring2 = feval(datalabelformatfcnh,xv2,yv2);
%Add the data label
th1 = text(xv1,yv1,textstring1,'FontSize',8,'Tag','CursorText','Parent',axh);
th2 = text(xv2,yv2,textstring2,'FontSize',8,'Tag','CursorText','Parent',axh);
%For R13 or higher (MATLAB 6.5), use a background color on the text string
v=ver('MATLAB');
v=str2num(v.Version(1:3));
if v>=6.5
set(th1,'BackgroundColor','y');
set(th2,'BackgroundColor','y');
end;
yl = ylim(axh);
lim = localObjbounds(axh);
lim = lim(3:4); %y values only
yl(isinf(yl)) = lim(isinf(yl));
%Add the cursors
ph1 = line([xv1 xv1 xv1],[yl(1) yv1 yl(2)], ...
'Color',color, ...
'Marker',marker, ...
'Tag','Cursor', ...
'UserData',[lineh th1], ...
'LineStyle','-', ...
'Parent',axh);
ph2 = line([xv2 xv2 xv2],[yl(1) yv2 yl(2)], ...
'Color',color, ...
'Marker',marker, ...
'Tag','Cursor', ...
'UserData',[lineh th2], ...
'LineStyle','-', ...
'Parent',axh);
%Add context menu to the cursors
% cmenu = uicontextmenu('Parent',get(axh,'Parent'));
cmenu = uicontextmenu('Parent',hFig);
set([ph1 ph2],'UIContextMenu',cmenu);
% Define the context menu items
item1 = uimenu(cmenu, 'Label', 'Export region to workspace', ...
'Callback', 'dualcursor(''exportws'',[],[],[],get(gco,''Parent''))');
item2 = uimenu(cmenu, 'Label', 'Export region to new figure', ...
'Callback', 'dualcursor(''exportfig'',[],[],[],get(gco,''Parent''))');
item3 = uimenu(cmenu, 'Label', 'Export cursor data to workspace', ...
'Callback', 'dualcursor(''exportcursor'',[],[],[],get(gco,''Parent''));');
item4 = uimenu(cmenu, 'Label', 'Turn cursors off', ...
'Callback', 'dualcursor(''off'',[],[],[],get(gco,''Parent''))', ...
'Separator','on');
setappdata(th1,'Coordinates',[xv1 yv1])