29 error(
" MAKEDATATIP:InvalidSize ",...
30 " HOBJ must be scalar. ");
35 error(
" MAKEDATATIP:InvalidHandle ",...
36 " HOBJ is an invalid handle object. ");
39 isImage = strcmp(
get(hObj,
" Type "),
" image ");
44 X =
get(hObj,
" XData ");
45 Y =
get(hObj,
" YData ");
48 error(
" MAKEDATATIP:InvalidObjectType ",...
49 " Objects of class "" %s "" are not a valid targets for datatips. ",...
53 Z =
get(hObj,
" ZData ");
62 elseif ~isnumeric(index)
63 error(
" MAKEDATATIP:InvalidDataType ",...
64 " Subscript indices must be of numeric data type. ")
65 elseif any(index(:)<1) ||...
66 any(fix(index(:))~=index(:)) ||...
68 error(
" MAKEDATATIP:InvalidIndex ",...
69 " Subscript indices must be positive integers. ")
70 elseif ~isvector(index) && ~any(size(index)==2)
71 error(
" MAKEDATATIP:InvalidIndexMatrixSize ",...
72 " Subscript indices must be a vector or N-by-2 matrix. ")
73 elseif (~isImage && isvector(
X)) || size(index,2)~=2
74 hDatatip = zeros(size(index));
78 hDatatip = zeros(size(index,1),1);
83 hDataCursorMgr = datacursormode(ancestor(hObj,
" figure "));
86 for n = 1:size(index,1)
89 if isImage && isLinear
90 [i j] = ind2sub([
X(2)
Y(2)], index(n));
93 pos = [index(n, 1) index(n, 2) 1];
95 pos = [
X(index(n))
Y(index(n))];
97 pos = [
X(index(n))
Y(index(n)) Z(index(n))];
100 X(index(n,1),index(n,2))...
101 Y(index(n,1),index(n,2))...
102 Z(index(n,1),index(n,2))];
106 hDatatip(n) = createDatatip(hDataCursorMgr, hObj);
109 set(
get(hDatatip(n),
" DataCursor "),
" DataIndex ",pos,...
110 " TargetPoint ",pos(1:2))
112 set(
get(hDatatip(n),
" DataCursor "),
" DataIndex ",index(n, :),...
117 set(hDatatip(n),
" Position ",pos)
122 updateDataCursors(hDataCursorMgr)
Matlab's base handle class (documentation generation substitute)
function varargout = makedatatip(hObj, index)
MAKEDATATIP Adds data tips to specified data points of graphical objects.
A variable number of output arguments.