For Programmers: Free Programming Magazines  


Home > Archive > Matlab > January 2008 > Trace Position of Cursor without Click Mouse GPOS









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Trace Position of Cursor without Click Mouse GPOS
Frank Pezzulo

2008-01-30, 8:20 pm

DEAR ALL,

my problem is to use function "gpos" that you can get to
File Exchange.

Can i have an example code to run this function ... I try
with my example but doesn't work. Thanks

My Example is:

t = (0:0.05:1)';
d1 = sin(2*pi*t)*[1 2 3];
d2 = cos(2*pi*t)*[1 2 3];
h=plot(t,[d1 d2]);
gpos(h)
set(h,'WindowButtonMotionFcn',@gpos)

Thank you very much to all have help me until now!!!

Frank
Walter Roberson

2008-01-30, 8:20 pm

In article <fnqd12$m0c$1@fred.mathworks.com>,
Frank Pezzulo <john.doe.nospam@mathworks.com> wrote:

>my problem is to use function "gpos" that you can get to
>File Exchange.


>Can i have an example code to run this function ... I try
>with my example but doesn't work.


What happens instead of it working? Telling us that something
"doesn't work" is not usually useful to us; we need to know what
you observed when you tried to run it.
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
Frank Pezzulo

2008-01-30, 11:14 pm

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fnqdnl$ikg$1@canopus.cc.umanitoba.ca>...
> In article <fnqd12$m0c$1@fred.mathworks.com>,
> Frank Pezzulo <john.doe.nospam@mathworks.com> wrote:
>
>
>
> What happens instead of it working? Telling us that something
> "doesn't work" is not usually useful to us; we need to

know what
> you observed when you tried to run it.
> --
> "There are some ideas so wrong that only a very

intelligent person
> could believe in them." --

George Orwell





IT SHOWS ONLY PLOT WITH LINE BUT FUNCTION gpos DOESN'T WORK!
MAYBE I HAVE WRONG TO USE THE LINE
set(h,'WindowButtonMotionFcn',@gpos) ????


Walter Roberson

2008-01-30, 11:14 pm

In article <fnqd12$m0c$1@fred.mathworks.com>,
Frank Pezzulo <john.doe.nospam@mathworks.com> wrote:

>my problem is to use function "gpos" that you can get to
>File Exchange.


>Can i have an example code to run this function ... I try
>with my example but doesn't work. Thanks


>My Example is:


>t = (0:0.05:1)';
>d1 = sin(2*pi*t)*[1 2 3];
>d2 = cos(2*pi*t)*[1 2 3];
>h=plot(t,[d1 d2]);
>gpos(h)
>set(h,'WindowButtonMotionFcn',@gpos)


Looks to me like you failed to read the documentation at the
beginning of the gpos.m source file. I should push you some more
to say what you expected your sample code to *do*, but I don't
have the energy at the moment for enough exchanges to help you
realize for yourself what is going wrong. So here is an adjusted
example that should do something visible, even if it wasn't what
you expected.

Put this in testgpos.m and then invoke
testgpos
from the command line:


function testgpos
%As you move your cursor around, the updated cursor position should
%be displayed in the command window.
t = (0:0.05:1)';
d1 = sin(2*pi*t)*[1 2 3];
d2 = cos(2*pi*t)*[1 2 3];
plot(t,[d1 d2]);
set(gcf, 'WindowButtonMotionFcn', {@displaypos, gca});
end

function displaypos(src, evt, whichaxis)
[x y] = gpos(whichaxis);
disp(sprintf('cursor now at: %g %g\n', x, y));
end



Important hints:

- gpos() requires an axis as input. plot() returns a lineseries,
not an axis, so h=plot() followed by gpos(h) is wrong because
you would be passing a lineseries handle to gpos instead of an axis.

- calling gpos by itself outside of the callback does not
do anything useful for you.

- gpos() returns two values, not an array of two values.

- The gpos.m source indicates,

% 2. It works like GINPUT provided by Matlab,but it traces the position
% of cursor without click and is designed for 2-D axes.

Here, 'traces the position' should be read as meaning
'follows and returns the position', not as
meaning that it will draw anything on the plot.
--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
Frank Pezzulo

2008-01-31, 8:28 pm

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fnqsb7$679$1@canopus.cc.umanitoba.ca>...
> In article <fnqd12$m0c$1@fred.mathworks.com>,
> Frank Pezzulo <john.doe.nospam@mathworks.com> wrote:
>
>
>
>
>
> Looks to me like you failed to read the documentation at the
> beginning of the gpos.m source file. I should push you

some more
> to say what you expected your sample code to *do*, but I don't
> have the energy at the moment for enough exchanges to help you
> realize for yourself what is going wrong. So here is an

adjusted
> example that should do something visible, even if it

wasn't what
> you expected.
>
> Put this in testgpos.m and then invoke
> testgpos
> from the command line:
>
>
> function testgpos
> %As you move your cursor around, the updated cursor

position should
> %be displayed in the command window.
> t = (0:0.05:1)';
> d1 = sin(2*pi*t)*[1 2 3];
> d2 = cos(2*pi*t)*[1 2 3];
> plot(t,[d1 d2]);
> set(gcf, 'WindowButtonMotionFcn', {@displaypos, gca});
> end
>
> function displaypos(src, evt, whichaxis)
> [x y] = gpos(whichaxis);
> disp(sprintf('cursor now at: %g %g\n', x, y));
> end
>
>
>
> Important hints:
>
> - gpos() requires an axis as input. plot() returns a

lineseries,
> not an axis, so h=plot() followed by gpos(h) is wrong because
> you would be passing a lineseries handle to gpos instead

of an axis.
>
> - calling gpos by itself outside of the callback does not
> do anything useful for you.
>
> - gpos() returns two values, not an array of two values.
>
> - The gpos.m source indicates,
>
> % 2. It works like GINPUT provided by Matlab,but it

traces the position
> % of cursor without click and is designed for 2-D axes.
>
> Here, 'traces the position' should be read as meaning
> 'follows and returns the position', not as
> meaning that it will draw anything on the plot.
> --
> "Any sufficiently advanced bug is indistinguishable

from a feature."
> -- Rich Kulawiec




THANK YOU VERY MUCH ... I'VE RESOLVED.

REGARDS,

FRANCESCO

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com