How to enable the data tip interaction functionality when using a custom "ButtonDownFcn" in MATLAB R2023a?
7 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2024-3-22
编辑: MathWorks Support Team
2024-3-26
I am using MATLAB R2023a, and I have a custom "ButtonDownFcn" to display the point clicked in the plot.
x = linspace(0,2*pi,100);
y = sin(x);
p = plot(x,y);
xlabel('x');
ylabel('sin(x)');
% Custom ButtonDownFcn to display point clicked
set(p,'ButtonDownFcn',{@buttondownfcn});
function buttondownfcn(~,event)
pts = event.IntersectionPoint(1:2);
disp(pts);
end
However, I notice that when using a custom "ButtonDownFcn", I no longer have the default interactivity of a plot (e.g., displaying data tip upon hovering, etc.). How can I enable the data tip interaction functionality when using a custom "ButtonDownFcn"?
采纳的回答
MathWorks Support Team
2024-3-26
编辑:MathWorks Support Team
2024-3-26
Currently, the "ButtonDownFcn" callback does not have the functionality to enable data tip interaction. To enable the data tip interaction functionality in MATLAB R2023a, consider using the "Hit" event instead of a "ButtonDownFcn". Please see the following code snippet for an example.
x = linspace(0,2*pi,100);
y = sin(x);
p = plot(x,y);
xlabel('x');
ylabel('sin(x)');
% Add a Hit event listener
addlistener(p,'Hit',@(src,event)buttondownfcn(src,event));
function buttondownfcn(~,event)
pts = event.IntersectionPoint(1:2);
disp(pts);
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!