how to restrict datacursormode in gui to be active only in one axis.

4 次查看(过去 30 天)
Hi people.
Hope you are feeling well with all that situation. I did some gui with two axes. In one I present the image and in another one the graphs from that image. I need datacursormode will move and be active only in the axes with image, because right now the datacursormode is active also in the axes with graphs which is not good for my situation (actually it's active in the whole figure).
Thank you very much.

采纳的回答

Adam Danz
Adam Danz 2020-3-22
编辑:Adam Danz 2020-3-23
datacursormode toggles the data cursor functionality for an entire figure, not for specific axes.
A workaround to controlling datacursormode for specific axes is to turn off the handle visibility for the axes that should not have datacursor capabilities.
Note that this may affect other functions in your gui that depend on handle visibility so it should be tested thoroughly.
set(axisHandle,'HandleVisibility','Off')

更多回答(1 个)

Dimani4
Dimani4 2020-3-23
Adam,
Thank you. I'll try it out. Actually I just thought about just datacursormode off option when I'll do something in another picture and then again bring it back by datacursormode on.
  2 个评论
Adam Danz
Adam Danz 2020-3-23
编辑:Adam Danz 2020-3-24
That's a good way of controlling when the user may use the datacursor but when it's active, it will be active on all axes within the figure. Just FYI.
Dimani4
Dimani4 2020-3-24
编辑:Dimani4 2020-3-24
I just did what I said before. I just do datacursormode off when I want to use dualcursor function on graph. But anyway I add in the function when you click on the graph the cursor shows you data on the graph. Just wanted to add here about disabling the datacursormode: before disabling do command:[your handle to datacursormode].removeAllDataCursors() and then datacursormode off. It will remove completely the datacursor from your figure.
handles.dcm_obj = datacursormode(hObject.Parent);
handles.dcm_obj.Enable='on';
set(handles.dcm_obj,'DisplayStyle','datatip','UpdateFcn',{@updatefcn,hObject,handles});
%-------------------------------------------------------
function txt=updatefcn(~,event_obj,hFigure,handles)
curInfo = getCursorInfo(handles.dcm_obj);
WhereIsCursor=get(curInfo.Target,'Type');%here if you click on image the output of that function will be image
if strcmp(WhereIsCursor,'image')==1
txt = {['Colunm: ',num2str(pos(1))],['Row: ',num2str(pos(2))]};
txt_string='Row:%s\nColumn:%s';
curr_pix=sprintf(txt_string,num2str(pos(2)),num2str(pos(1)));
elseif strcmp(WhereIsCursor,'line')==1
pos1 = get(event_obj,'Position');
txt = {['Wavelength: ',num2str(pos1(1))],['Intensity: ',num2str(pos1(2))]};
end
%----------------------------------------------------------

请先登录,再进行评论。

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by