点击MATLAB绘图标记绘图子图

时间:2012-04-20 15:46:58

标签: matlab plot interactive marker clickable

在Matlab 2011b中,我有一个多维矩阵,最初将其显示为2个维度的2D图。我希望用鼠标左键点击标记。单击标记将绘制按所单击值切割的其他维度的新图形。

这个问题与Matlab: Plot points and make them clickable to display informations about it有关,但我想运行一个脚本,而不只是弹出有关点击点的数据。

谷歌搜索暗示可以使用ButtonDownFcn,但我发现的例子需要手动绘制每个点并附加处理程序,如下所示:

hp = plot(x(1), y(1), 'o');
set(hp, 'buttondownfcn', 'disp(1)');

由于主图中有许多标记,是否可以将处理程序附加到整个曲线并使用索引(首选)或点击标记的坐标来调用子图绘制函数?

1 个答案:

答案 0 :(得分:3)

这是您需要的一个想法,如果我了解您的要求,应该帮助您入门。

在这种情况下,当你选择一条曲线时,它会在底部的子图中绘制它,保留颜色。

function main
subplot(211)
h = plot (peaks);

set (h,'buttondownfcn', @hitme)
end

function hitme(gcbo,evendata)
subplot (212)
hold on;

col = get (gcbo,'Color');
h2 =  plot (get (gcbo,'XData'),get (gcbo,'YData'));
set (h2,'Color', col)

pt = get (gca, 'CurrentPoint');
disp (pt);
end

只需在get(gcbo)函数中撰写hitme,即可探索获取选项。

相关问题