[~,~,button] = ginput(1); PROBLEM
3 次查看(过去 30 天)
显示 更早的评论
[~,~,button] = ginput(1);
PROBLEM: when pressing right button, the contextual window of windows (with actions like Watch, Order By...) keeps appearing.
How can I solve this problem?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1539082/image.png)
4 个评论
回答(1 个)
Yatharth
2023-12-8
Hi Javier,
I understand that the issue you are encountering is related to the behavior of the contextual window that appears when using the "ginput" function to capture mouse clicks in MATLAB. The contextual window in Windows might interfere with the intended usage of ginput for segmenting muscular contractions in your figure.
I tried reproducing the error and did not face the issue in the 2021b or 2023b release.
Here is an alternative approach to handle mouse clicks for segmenting the muscular contractions. One alternative is to use the "ButtonDownFcn" property of the figure to capture mouse clicks without the interference of the contextual window.
% Predefined data for plotting
data1 = rand(100,1); % Sample data for muscle 1
data2 = rand(100,1); % Sample data for muscle 2
% Create a figure with subplots representing muscles
fig = figure;
subplot(2, 1, 1);
plot(data1);
title('Muscle 1');
subplot(2, 1, 2);
plot(data2);
title('Muscle 2');
% Set the ButtonDownFcn for the figure to capture mouse clicks
set(fig, 'ButtonDownFcn', @handleMouseClick);
function handleMouseClick(src, event)
button = get(gcf, 'SelectionType');
if strcmp(button, 'normal') % Left-click
[x, ~] = ginput(1); % Capture the x-coordinate of the click
% Store the x-coordinate for further processing
disp(['Left-click at x = ', num2str(x)]);
elseif strcmp(button, 'alt') % Right-click
% Handle the right-click action (e.g., skip the current swallow)
disp('Right-click detected');
end
end
If you are comfortable, you can share your code and data here along with the reproduction steps, and I can investigate further. Alternatively, you may choose to reach out to MathWorks for technical support.. https://www.mathworks.com/support/contact_us.html
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!