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

7 ビュー (過去 30 日間)
Dimani4
Dimani4 2020 年 3 月 22 日
編集済み: Dimani4 2020 年 3 月 24 日
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