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

11 views (last 30 days)
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.

Accepted Answer

Adam Danz
Adam Danz on 22 Mar 2020
Edited: Adam Danz on 23 Mar 2020
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')

More Answers (1)

Dimani4
Dimani4 on 23 Mar 2020
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 Comments
Adam Danz
Adam Danz on 23 Mar 2020
Edited: Adam Danz on 24 Mar 2020
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 on 24 Mar 2020
Edited: Dimani4 on 24 Mar 2020
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
%----------------------------------------------------------

Sign in to comment.

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!