This function enables a graphical object (be it a line, plot, patch, rectangle, text box, etc.) to be dragged inside an axis, with a very simple syntax ("draggable(h)"), following or not horizontal, vertical or diagonal constraints. Limits can be imposed on the object's movement.
Some figure properties are changed by the function, but previous properties are restored as soon as the drag is stopped. The behavior of the object can be reverted to its original, non-draggable state, by issuing "draggable(h,'off')".
Typical uses of this function would include non-standard GUI elements, such as markers that are moved on a figure or image. A function which is called when the object is moved can be provided as an optional argument, so that the movement triggers further actions.
See the provided file dragdemo.m for usage examples.
Francois Bouffard (2021). draggable (https://www.mathworks.com/matlabcentral/fileexchange/4179-draggable), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired: colorStudioMax: ColorBrowser+dictionary, colorBlind correct, DragDataTip, roitool, DIGITIZE07, Enhanced Dicom Viewer, imdisp (enhanced version), Add an ROI toolbar to your figure, draggableRect, AVPlay
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!