代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85function crossget ezplot('sin(x)'); set(gcf,'pointer','crosshair'); set(gcf,'WindowButtonMotionFcn',@tempfcn2); function tempfcn2(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) +0.5,p(3)]); else ht = findobj('tag','htext'); set(ht,'string',sprintf('(%g, %g)', p(1), p(3)),'position',[p(1)+0.5,p(3)]); end %也可以响应鼠标点击取点,例如: function crosshair ezplot('sin(x)'); set(gcf,'Pointer','crosshair'); set(gcf,'WindowButtonDownFcn',@myfcn); flag=1; xlim=get(gca,'xlim'); xlim=[xlim(2)-xlim(1)]*0.025; ylim=get(gca,'ylim'); ylim=[ylim(2)-ylim(1)]*0.03; set(gcf,'userdata',[flag,xlim,ylim]); %---------------- function myfcn(hObject, eventdata, handles); pt=get(gca,'currentpoint'); pt_show=[pt(1,1),pt(1,2)] temp=get(gcf,'userdata'); if iscell(temp) H=temp{2}; temp=temp{1}; end flag=temp(1);xlim=temp(2);ylim=temp(3); if flag==1 H.xline=line([pt(1,1)-xlim,pt(1,1)+xlim],[pt(1,2),pt(1,2)]); H.yline=line([pt(1,1),pt(1,1)],[pt(1,2)-ylim,pt(1,2)+ylim]); flag=0; else set(H.xline,'xdata',[pt(1,1)-xlim,pt(1,1)+xlim]); set(H.xline,'ydata',[pt(1,2),pt(1,2)]); set(H.yline,'xdata',[pt(1,1),pt(1,1)]); set(H.yline,'ydata',[pt(1,2)-ylim,pt(1,2)+ylim]); end set(gcf,'userdata',{[flag,xlim,ylim],H}); %以上响应鼠标点击取点,是在matlab窗口中显示坐标值,也是我在论坛中搜索并整理的。实际上,根据不同的需要,只要稍加改动,就可以实现不同功能,如要在图形上记录坐标只需如下改动: function crosshair ezplot('sin(x)'); set(gcf,'Pointer','crosshair'); set(gcf,'WindowButtonDownFcn',@myfcn); flag=1; xlim=get(gca,'xlim'); xlim=[xlim(2)-xlim(1)]*0.025; ylim=get(gca,'ylim'); ylim=[ylim(2)-ylim(1)]*0.03; set(gcf,'userdata',[flag,xlim,ylim]); function myfcn(hObject, eventdata, handles); pt=get(gca,'currentpoint'); text('string',sprintf('(%g, %g)', pt(1), pt(3)),'position',[pt(1)+0.5,pt(3)]); temp=get(gcf,'userdata'); if iscell(temp) H=temp{2}; temp=temp{1}; end flag=temp(1);xlim=temp(2);ylim=temp(3); if flag==1 H.xline=line([pt(1,1)-xlim,pt(1,1)+xlim],[pt(1,2),pt(1,2)]); H.yline=line([pt(1,1),pt(1,1)],[pt(1,2)-ylim,pt(1,2)+ylim]); flag=0; else set(H.xline,'xdata',[pt(1,1)-xlim,pt(1,1)+xlim]); set(H.xline,'ydata',[pt(1,2),pt(1,2)]); set(H.yline,'xdata',[pt(1,1),pt(1,1)]); set(H.yline,'ydata',[pt(1,2)-ylim,pt(1,2)+ylim]); end %----------------------- %-----------------------
来源:http://zhidao.baidu.com/question/153115768
最后
以上就是爱笑万宝路最近收集整理的关于matlab中如何得到图像的坐标的全部内容,更多相关matlab中如何得到图像内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复