Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

user interface - uicontextmenu inaccessible when using pcolor and contourf (MATLAB R2014b)

I am not especially experienced with MATLAB so this might be a dumb question, but I would appreciate any help that can be given.

I have some code that creates some axes, assigns a uicontextmenu to said axes, and then plots a graph of the user's choosing on the axes. The uicontextmenu is accessible by right-clicking on the graphs (as it should be) in every plot case it needs to EXCEPT for pcolor and contourf. Why would this be? Is there any way I can get around this?

Through extensive debugging I have found that the uicontextmenu is accessible until the pcolor (or contourf) functions are called and then it disappears. What am I missing?

EDIT: As requested, example code below. If you use pcolor the uicontextmenu won't appear and if you use plot then it will. I think it has something to do with the data the cursor is highlighting. If your cursor right clicks on plotted data, nothing appears in both. But why is this?

axes;

stuff = uicontextmenu('Parent',ancestor(axes,'figure'));
stuffm = uimenu('Parent',stuff,'Label','Change something');
set(axes,'uicontextmenu',stuff);

x = randn(10);
y1=randn(10,1);
y2=randn(10,1);


plot(y1,y2)
%pcolor(x)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The pcolor function creates a surface graphics object which has its own uicontextmenu property. You have to set it after the pcolor returns the surface handle:

h= pcolor(x);
set(h,'uicontextmenu',stuff);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...