[問題] GUI裡各BUTTON的參數傳遞
我在某個BUTTON_A點下去會呼叫一個寫好的pick.m檔 用來在圖上點標記點。
然後我想記錄這些標記點的位置,我用了setappdata去存。
然後我想要按下BUTTON_B時可以抓到setappdata的資料。
但試了好多方法都還是不行。
有沒有高手可以給我一點指導。感謝。
GUI:
function BUTTON_A_Callback(hObject, eventdata, handles)
% hObject handle to FeaturePoint (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pick('照片.jpg');
% --- Executes on button press in fpok.
function BUTTON_B_Callback(hObject, eventdata, handles)
% hObject handle to fpok (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
globe fpoutput
fpoutput=getappdata(0,'Out')
------------------------------------------------------------------------
pick.m:
function pick(img_filename)
global height;
global width;
global out;
out=[]
A=imread(img_filename);
height=size(A,1);
width=size(A,2);
imshow(A);
hold on;
im_h=imhandles(gcf);
set(im_h,'ButtonDownFcn',@pick_point);
function pick_point(~,~)
c_p=get(gca,'CurrentPoint');
plot(c_p(1,1),c_p(1,2),'r+');
TP=[c_p(1,1),c_p(1,2)];
TP(1)=TP(1)/width;
TP(2)=1-(TP(2)/height);
disp(TP);
out(end+1,:)=TP;
setappdata(0,'Out',out);
end
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.114.54.47
※ 編輯: DoUBLE 來自: 140.114.54.47 (10/30 11:57)