假设GUI中有两个axes,并设置全局变量:P11,P12,P2
axes1的曲线为P11(X11,Y11) P12(X12,Y12)
axes2的曲线为P2(X2,Y2)
1.实时获取游标位置事件的全局变量
function figure1_WindowButtonMotionFcn(hObject,eventdata,handles)
global Pos;
Pos=get(gcf,'CurrentPoint');
2.通过判断位置Pos(x,y)坐标,显示axes中的内容
function txt=MyDataCursorUpdata(obj,event_obj)
pos=get(event_obj,'Position'); %%当前axes中x的坐标
global Pos; %%全局游标位置
global P11 P12 P2; %%全局游标位置
%%120通过测试调整,为axes1何axes2之间x坐标某一分割值
if Pos(1)<120
x=num2str(pos(1));
str11=num2str(P11(pos(1)),'%0.6f%%');
str12=num2str(P12(pos(1)),'%0.6f%%');
txt={['pos:',x],['plot11:',str11],['plot12:',str12]};
else
x=num2str(pos(1));
str2=num2str(P2(pos(1)),'%0.6f%%');
txt={['pos:',x],['plot2:',str2]};
end
3.方法绑定
dcm_obj=datacursormode(gcf);
set(dcm_obj,'DisplayStyle','datatip','Enable','on');
set(dcm_obj,'UpdateFcn',@MyDataCursorUpdata);
Matlab中datacursormode实时显示axes中的标签(tip)内容
最新推荐文章于 2024-06-18 19:14:15 发布