Hi,
I've set the 'WindowButtonDownFcn' in my GUI opening function as below:
set(gcf, ... 'WindowButtonDownFcn', @clickFcn, ... 'WindowButtonUpFcn', @unclickFcn);
The @clickFcn looks like that below, with a Drag function within it:
function clickFcn(hObject, eventdata, handles)allAxes = findobj(gcf, 'Type', 'axes');hCur = nan(1, length(allAxes)); for id = 1:length(allAxes) hCur(id) = line([NaN NaN], ylim(allAxes(id)), ... 'Color', 'black', 'Parent', allAxes(id)); end % Initiate cursor if clicked anywhere but the figure
if strcmpi(get(gco, 'type'), 'figure') set(hCur, 'XData', [NaN NaN]); % <-- EDIT
set(hText, 'Position', [NaN NaN]); % <-- EDIT else set(gcf, 'WindowButtonMotionFcn', @dragFcn) dragFcn(); end
The drag function is:
function dragFcn(varargin) % Get mouse location
pt = get(gca, 'CurrentPoint'); % Update cursor line position
set(hCur, 'XData', [pt(1), pt(1)]); % Update cursor text
for idx = 1:length(allLines) xdata = get(allLines(idx), 'XData'); ydata = get(allLines(idx), 'YData'); if pt(1) >= xdata(1) && pt(1) <= xdata(end) y = interp1(xdata, ydata, pt(1)); set(hText(idx), 'Position', [pt(1), y], ... 'String', sprintf('(%0.2f, %0.2f)', pt(1), y)); else set(hText(idx), 'Position', [NaN NaN]); end end
When I click on the plot, I realized the clickfunction could not detect them. I've handles from other callbacks as below:
K>> handleshandles = figure1: [1x1 Figure] clear_all: [1x1 UIControl] uipanel1: [1x1 Panel] uipanel2: [1x1 Panel] uipanel4: [1x1 Panel] uipanel5: [1x1 Panel] LoadFile: [1x1 UIControl] pop_filelist: [1x1 UIControl] var_list: [1x1 UIControl] togglepan: [1x1 UIControl] togglezoom: [1x1 UIControl] selected_varlist2: [1x1 UIControl] add_var2: [1x1 UIControl] plot2_push: [1x1 UIControl] selected_varlist1: [1x1 UIControl] add_var1: [1x1 UIControl] plot1_push: [1x1 UIControl] axes2: [1x1 Axes] axes1: [1x1 Axes] text6: [1x1 UIControl] select_folder: [1x1 UIControl] text5: [1x1 UIControl] output: [1x1 Figure] b: 0 folder: 'C:\Users\r14ang\Documents\MATLAB' count: 1 count2: 1 files: [9x1 struct] selected_file: 'C:\Users\r14ang\Documents\MATLAB\TZ24SKE_SCOP_F_Cut3.csv' selected_file_table: [3930x33 table] variable_list: {1x33 cell} sel_list_temp: {'ODPIPESENSOR'} sel_list_temp2: {'COMPTEMP'} time_sec2: [1x3930 double]
What have I done incorrectly?
Thanks in advance.
Best Answer