马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
其中windowbuttonmotionfcn部分内容参考Genial的思路
- function GetMousePointer
- global handles
- clc
- close all
- hMainFig=figure('name','鼠标捕捉点坐标','number','off','menubar','none',...
- 'units','normalized','tag','hMainFig');
- set(hMainFig,'units','normalized','position',[.2,.2,.6,.6]);
- set(hMainFig,'defaultuicontrolfontname','隶书');
- set(hMainFig,'defaultuicontrolfontsize',13);
- set(hMainFig,'defaultuicontrolunits','normalized');
- hAxes=axes('position',[.15,.2,.8,.7]);
- ezplot('sin(x)');
- set(hMainFig,'pointer','cross');
- set(hMainFig,'WindowButtonMotionFcn',@ShowPointData);
- hText11=uicontrol(hMainFig,'style','text','position',[.05,.05,.1,.1],'string','x:');
- hText12=uicontrol(hMainFig,'style','text','position',[.15,.05,.25,.1],'tag','hText12');
- hText21=uicontrol(hMainFig,'style','text','position',[.45,.05,.1,.1],'string','y:');
- hText22=uicontrol(hMainFig,'style','text','position',[.55,.05,.25,.1],'tag','hText22');
- handles=guihandles(hMainFig);
- guidata(hMainFig,handles);
- set(hMainFig,'windowButtonDownFcn',@WritePointData)
- function WritePointData(hObject, eventdata, handles)
- global handles
- p=get(gca,'currentpoint');
- set(handles.hText12,'string',num2str(p(1)))
- set(handles.hText22,'string',num2str(p(3)))
- function ShowPointData(hObject, eventdata, handles)
- p=get(gca,'currentpoint');
- if(isempty(findobj('tag','htext')))
- ht=text('tag','htext','string',sprintf('(%g, %g)', p(1), p(3)),'position',[p(1),p(3)]);
- else
- ht = findobj('tag','htext');
- set(ht,'string',sprintf('(%g, %g)', p(1), p(3)),'position',[p(1)+.1,p(3)+.1]);
- end
复制代码
[ 本帖最后由 bainhome 于 2006-9-3 22:27 编辑 ] |