是否可以在给定的图形上创建数据光标并将其他图形中的光标链接到它?(不是子图)
目标是,当我手动移动其中一个光标的位置时,所有其他图形中的数据光标都会平行移动到相同的位置(假设所有图形的大小相同)。
是否可以在给定的图形上创建数据光标并将其他图形中的光标链接到它?(不是子图)
目标是,当我手动移动其中一个光标的位置时,所有其他图形中的数据光标都会平行移动到相同的位置(假设所有图形的大小相同)。
可以使用未公开的MATLAB函数实现。诀窍在于捕获数据提示更改的时机,然后相应地更新其他内容。
下面展示了两个链接图的概念证明:
% first plot
f1 = figure;
p1 = plot(1:10);
datacursormode on; % enable datatip mode
c1 = datacursormode(f1); % get the cursor mode
d1 = c1.createDatatip(p1); % create a new datatip
% second plot
f2 = figure;
p2 = plot(1:10);
datacursormode on;
c2 = datacursormode(f2);
d2 = c2.createDatatip(p2);
% register the function to execute when the datatip changes.
set(d1,'UpdateFcn',@(cursorMode,eventData) onDataTipUpdate(cursorMode,eventData, d2))
set(d2,'UpdateFcn',@(cursorMode,eventData) onDataTipUpdate(cursorMode,eventData, d1))
% callback function when the datatip changes
function displayText = onDataTipUpdate(cursorMode,eventData, d)
pos = get(eventData,'Position'); % the new position of the datatip
displayText = {['X: ',num2str(pos(1))], ...
['Y: ',num2str(pos(2))]}; % construct the datatip text
d.Position(1) = pos(1); % update the location of the other datatip.
end
p1 = plot(1:10)
更改为p1 = imshow(im1)
,将p2 = plot(1:10)
更改为p2 = imshow(im2)
,并在d.Position(1) = pos(1)
下方添加d.Position(2) = pos(2)
。 - Prefect