Code covered by the BSD License  

Highlights from
Moveit2 - Move a graphical object with the mouse.

4.75

4.8 | 4 ratings Rate this file 11 Downloads (last 30 days) File Size: 1.67 KB File ID: #23304
image thumbnail

Moveit2 - Move a graphical object with the mouse.

by Anders Brun

 

16 Mar 2009

Move graphical objects with your mouse. Works for pcolor, plot, patches and perhaps more.

| Watch this File

File Information
Description

This is really a small hack that I wanted to share just to inspire more people to make interactive Matlab graphics. Use it as is or use the code as a template to do more advanced stuff.

Here is how it works (for a 2-D patch):

% First make the patch ...
    t = 0:2*pi/20:2*pi;
    X = 3 + sin(t); Y = 2 + cos(t); Z = X*0;
    h = patch(X,Y,Z,'g')
    axis([-10 10 -10 10]);
% Then make it movable
    moveit2(h);
 
It also works for e.g. pcolor and plot:

% Adjust data to fit hypothesis using the mouse ... :-)
a = plot(rand(10,10));
moveit2(a);

Acknowledgements
This submission has inspired the following:
Move a 3D object with mouse in a traditional 4-view window
MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
16 Mar 2009 Jveer  
16 Mar 2009 Jveer

5* for simplicity

17 Mar 2009 Anders Brun

thanks a lot for the 5 star... Just a comment, there are still things that can be simplified. In particular I think it would be possible to store state of the object in a smarter and even more invisible way, instead of using the UserData attributes. Perhaps a global variable with an obscure name would do it.

23 Oct 2009 Jan Simon

No, please do not use a global variable. The need of an obscure name is a warning already! I'd suggest using the ApplicationData of the object, see setappdata.
Itr would restore the original WindowButtonMotionUp functions after your function is finished.
H1-Line, comments, it works.

01 Nov 2009 Jan Simon

Sorry, too confusing typos.
If the original WindowButton-Motion/-Up functions are restored after your function has finished, I will rate it with 5 stars.

02 Jul 2010 Gang Wang

Hi Anders, I am using Moveit2 and find this interactive tool is great!

For my curiosity, I produced a 3D object patch (triangulated) and input to the function.

It can be observed that the object translates on XY plane. But the shape of the object is no longer preserved.

I did debugging and observed that the size of 'Vertices' matrix under the gui.currenthandle is automatically changed after line 66:
set(gui.currenthandle,'XData',XYData{1} + pos(1,1));

In other words, if the size of 'X' or 'YData' is [3 by 100];
then the new vertices size will always be updated to [3*100 by 3].

I guess some private functions updates the 'Vertices' whenever the XYZData is changed. But I cannot find the mechanism behind this.

10 Jan 2011 Jonathan  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
gui Anders Brun 16 Mar 2009 12:42:20
mouse Anders Brun 16 Mar 2009 12:42:20
move Anders Brun 16 Mar 2009 12:42:20
gui Yogish Didgi 06 Jan 2011 05:23:13
mouse Jason Zhang 11 Mar 2011 01:43:54
move Jason Zhang 11 Mar 2011 01:43:56
gui Jason Zhang 11 Mar 2011 01:44:00

Contact us at files@mathworks.com