matlab gui 鼠标选择矩形区域 返回鼠标坐标点
生活随笔
收集整理的这篇文章主要介绍了
matlab gui 鼠标选择矩形区域 返回鼠标坐标点
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1.鼠标选择矩形区域
--- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) hObject handle to pushbutton1 (see GCBO) eventdata reserved - to be defined in a future version of MATLAB handles structure with handles and user data (see GUIDATA)I=imread('pic_gui_I.bmp','bmp'); axes(handles.axes1); image(I) axis off; mp= handles.activex1; % activex1 为调用的WMP的handle。 %画图后: h=imrect;%鼠标变成十字,用来选取感兴趣区域---------------------------------------- %图中就会出现可以拖动以及改变大小的矩形框,选好位置后: ---------------------------------------- pos=getPosition(h);---------------------------------------- %pos有四个值,分别是矩形框的左下角点的坐标 x y 和 框的 宽度和高度 ---------------------------------------- ---------------------------------------- %拷贝选取图片 ---------------------------------------- imCp = imcrop( I, pos ); figure(2) imshow(imCp);2. 返回鼠标坐标点
function main() global line; global h1; global flag; flag=0; line=rand(1,100); h1=plot(line); hold on set(h1,'ButtonDownFcn',@clicky); h2 = uicontrol('style','text','Position',[30 15 100 30],'string','此处显示选中点的坐标');function clicky(varargin) %鼠标点击时触发该事件 global h_point global line; global flag; if flagset(h_point,'Visible','off'); end a=get(gca,'Currentpoint'); for i=1:2ai=a(1,i); if ceil(ai)-ai>ai-floor(ai)b(1,i)=floor(ai); elseb(1,i)=ceil(ai); end end h_point=plot(gca,b(1,1),line(b(1,1)),'r*'); if ~isempty(h_point)flag=1; end set(findobj('style','text'),'String',strcat('x:',num2str(b(1,1)),' y:',num2str(line(b(1,1))))); 《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读总结
以上是生活随笔为你收集整理的matlab gui 鼠标选择矩形区域 返回鼠标坐标点的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Latex 设置文字大小
- 下一篇: matlab下删除文件或文件夹