1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| function drag_line(app, fig, sel_line) sel_line.ButtonDownFcn = @bdfcn; opx = 0; function bdfcn(~, edata) opx = edata.IntersectionPoint(1); sel_line.Selected = 'on'; app.UIFigure.WindowButtonMotionFcn = @wbmfcn; app.UIFigure.WindowButtonUpFcn = @wbufcn; end function wbmfcn(~,~) cp = fig.CurrentPoint; dx = cp(1,1) - opx; newXData = sel_line.XData + dx; xLimits = fig.XLim; if all(newXData >= xLimits(1)) && all(newXData <= xLimits(2)) sel_line.XData = newXData; opx = cp(1,1); end app.LocationEditField.Value = sel_line.XData(1); end function wbufcn(~,~) app.UIFigure.WindowButtonMotionFcn = ''; app.UIFigure.WindowButtonUpFcn = ''; sel_line.Selected = 'off'; end end
arrayfun(@(ax) disableDefaultInteractivity(ax),[app.UIAxes]); xlim(app.UIAxes, [-10 10]); drag_line(app, app.UIAxes, plot(app.UIAxes, [0 0], [0 1], 'LineWidth', 2));
|