File Exchange

image thumbnail

Drag Patches Demo

version 1.0 (1.67 KB) by

shows how to create patches that can be clicked and dragged around



View License

This m-file demonstrates how to create patches that can be moved around when they are clicked on.

This functionality is ideal for interactive GUIs. For example, anyone who wants to write code for a board game with moving pieces could use this as a starting point.

Comments and Ratings (4)


Xiaoxi (view profile)

Iacopo Mochi

Very helpful! Thanks you very much!


Indeed, a canon called "WindowButtonMotionFcn" is able to kill any of several numbered in advance sparrows fixed at canon barrel. However, a more flexible tool, "moverotateobj" was published earlier.

Some remarks:
1. If I plot several patches, last plotted is usually in the upper layer. If I move patches by drag_patch, in fact I am plotting them anew. However, they do not appear as upper objects, and this is not consistent.

2. If I have many graphical objects, which are not in advance labeled by UserData, drag_patch will not work. This labeling is not always possible, e.g. if some object is added after creation of patches is finished. Moreover, any labeling in advance is not neseccary.

3. Moverotateobj works with line, patch and text objects, and drag_patch can be applied only to patch or line.

4. If you open FigurePalette, you can drag and rotate line and arrows, and drag and modify rectangle and ellipse (probably, in releases after R14 you can more). I do not know exactly whether there is a trick to drag and rotate user-plotted objects using FigurePalette options.

5. The file is not correctly called, because "drag" means that you press button, move the cursor and after button release the dragging is finished. With drag_patch, you have to click once more to finish.

6. So what's really new?

Questions to those who uses latest ML releases.

1. I should expect that any object in plane should be easily dragged and rotated as a standard option, because this (and more) is asked in practice. Is this still not the case?

2. Rectangle and ellipse from FigurePalette do not have Xdata and Ydata, as patch and line do. In addition they have no Rotation property. Is it reasonable to use special class of objects which is less general than existing standard line, patch or text?

This is not any criticism of drag_patch. I have my own versions of drag, rotate, explode etc., but I have expected to find something more flexible.

MATLAB Release
MATLAB 7.3 (R2006b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video