How to enable the data tip interaction functionality when using a custom "ButtonDownFcn" in MATLAB R2023a?

7 ビュー (過去 30 日間)
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
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 件)

タグ

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by