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 设置文字大小
- 下一篇: cvpr 2015 2016论文地址