是否可以在 MATLAB 中跨多个图形同步数据游标?
Is it possible to synchronize data cursors across multiple figures in MATLAB?
是否可以在给定图形的特定位置创建数据游标,然后 link 在其他图形中创建其他游标? (不是子图)
objective是当我手动移动这些游标之一的位置时,其他每个图中的所有其他数据游标都移动到与其平行的相同位置(假设所有图都是大小相同)。
可以使用 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
是否可以在给定图形的特定位置创建数据游标,然后 link 在其他图形中创建其他游标? (不是子图)
objective是当我手动移动这些游标之一的位置时,其他每个图中的所有其他数据游标都移动到与其平行的相同位置(假设所有图都是大小相同)。
可以使用 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