【问题标题】:Is it possible to synchronize data cursors across multiple figures in MATLAB?是否可以在 MATLAB 中跨多个图形同步数据游标?
【发布时间】:2017-09-28 23:33:50
【问题描述】:

是否可以在给定图形的某个位置创建数据游标,然后将其他图形中的其他游标链接到它? (不是子图)

目标是,当我手动移动其中一个光标的位置时,其他每个图形中的所有其他数据光标都会平行移动到相同的位置(假设所有图形的大小相同)。

【问题讨论】:

  • 您为什么要专门询问其他数据?有没有更简单的方法来处理同一个图的子图?

标签: matlab matlab-figure


【解决方案1】:

可以使用undocumented MATLAB functions。诀窍是捕捉数据提示何时更改并相应地更新其他提示。

下面显示了具有两个链接图的概念证明:

% 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

【讨论】:

  • 非常感谢您的回答。如果有人出于 2D 图像同步的目的需要此功能,请更改几行。 p1 = plot(1:10) >> p1 = imshow(im1)p2 = plot(1:10) >> p2 = imshow(im2) 并在 d.Position(1) = pos(1) 下方添加 d.Position(2) = pos(2)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
相关资源
最近更新 更多