[英]Buttondownfcn gui axes
我有一個Gui,它有一個軸...在軸上我可以用繪圖繪制線..但是我想選擇一個軸線..我嘗試了buttondownfcn ..但是它不起作用。我有一個按鈕DELETE,它的回調是:
hold all;
set(handles.axes6, 'HitTest', 'off');
set(handles.axes6,'ButtonDownFcn',('h = copyobj(gcbo,figure)'));
delete_object_axes = findobj(h, 'Type', 'line');
我的代碼是:
% --- Executes on mouse press over axes background.
function axes6_ButtonDownFcn(~, ~, handles)
% hObject handle to axes6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hold all;
set(handles.axes6, 'HitTest', 'off');
set(handles.axes6, 'ButtonDownFcn', {@Delete_Callback, handles}');
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonDownFcn(~, ~, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hold all;enter code here
global h;
set(handles.axes6, 'HitTest', 'off');
h = findobj(handles.axes6, 'Type', 'line');
set(h, 'ButtonDownFcn', {@Delete_Callback});
幫幫我..我如何選擇和刪除行??? 或移動??? 有某種方法可以做到嗎??? 對我來說很重要..請! 幫我!:)
以下是基於MATLABcentral中的討論的示例代碼,可以幫助您實現所需的目標 。 如果單擊某行,它所做的就是checl,如果您單擊了它,它將對其進行修改,如果再次單擊該行,它將被刪除。 您可以將其粘貼到文件中並運行。
function init()
close all; clear variables; clc;
ax1=ezplot('sin(x)');
set(ax1,'ButtonDownFcn',@mouseClick);
end
function mouseClick(source, event)
if strcmp(get(source,'Type'),'line')
if get(source,'linewidth')==2
delete(source);
return
end
%// Store the handle "source" someplace
%// Demonstration modification:
set(source,'linewidth',2);
end
end
編輯 :這是一個更復雜的示例,顯示了如何將變量保存到handles
結構(即guidata
):
function init()
close all; clear variables; clc;
hLine(1) = ezplot('sin(x)'); hold all; hLine(2) = ezplot('cos(x)');
set(hLine(:),'ButtonDownFcn',@mouseClick);
grid on
end
function mouseClick(hObject, eventdata)
handles = guidata(gcf); %#1
try
if handles.delete_object_axes==hObject;
delete(hObject);
handles = rmfield(handles,'delete_object_axes');
else
set(handles.delete_object_axes,'linewidth',1);
set(hObject,'linewidth',2);
handles.delete_object_axes = hObject;
end
catch
if strcmp(get(hObject,'Type'),'line')
handles.delete_object_axes = hObject;
set(hObject,'linewidth',2);
guidata(gca, handles);
else
set(handles.delete_object_axes,'linewidth',1);
end
return;
end
guidata(gca, handles);
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.