I am trying to set the position of the data cursor non-interactively.
I have two related images each having a custom data cursor function. I
am trying to link them so if the user changes the position of the data
cursor in one image, the data cursor in the other image is also
updated.
Is there a way to programmitcally send an event to the data cursor
object with the desired coordinates? Or is there a property that I can
change to achieve the same effect?
Thanks
Anup
Subject: How to set the position of the data cursor programmitcally
Anup Mantri:
<SNIP wants to link his/her data cursors...
one of the solutions is outlined below
- copy the snippet into <linkcur.m>
- at the command prompt, type
linkcur;
- move your mouse in the UPPER panel
us
function linkcur
% create the plots
sh(1)=subplot(2,1,1);
plot(rand(10,1));
sh(2)=subplot(2,1,2);
plot(rand(10,1));
% ... and the crosshair pointers
for i=1:2
xl{i}=get(sh(i),'xlim');
yl{i}=get(sh(i),'ylim');
lp{i}=line([xl{i};0,0].',[0,0;yl{i}].',...
'parent',sh(i),...
'color',[1,0,0]);
end
set(gcf,'windowbuttonmotionfcn',{@cb,sh,xl,yl,lp});
shg;
end
% the callback
function cb(h,e,sh,xl,yl,lp)
p=get(sh(1),'currentpoint');
for i=1:2
cp=max([xl{i}(1),p(1,1)]);
cp=min([xl{i}(2),cp]);
set(lp{i}(2),'xdata',[cp,cp]);
cp=max([yl{i}(1),p(1,2)]);
cp=min([yl{i}(2),cp]);
set(lp{i}(1),'ydata',[cp,cp]);
end
end
Subject: How to set the position of the data cursor programmitcally
You can use the linkprop function to link your data cursors'
xdata/ydata/zdata properties.
A related info bit (I know this is not what you asked) that
users may find interesting is how to programmatically move
the mouse cursor (pointer). The answer is to
set(0,'PointerLocation',newPosition) or to use the moveptr
function. Note: MathWorks considers moveptr as unsupported -
it's partly documented (it has a help section, but no doc
page), but when I tried reporting some internal bugs and
fixes to MathWorks I got the "undocumented & unsupported"
shrug-off... You need to pass it handle(hAx) where hAx is
your axes handle, and it works well in simple cases
(non-complicated GUIs). moveptr.m is editable and so can
easily be adapted by anyone interested.
On Aug 16, 2:08 pm, "us " <u...@neurol.unizh.ch> wrote:
> Yair Altman:
> <SNIP down to - questionable - advice... in the OP's
> context...
>
> > You can use the linkprop function to link your data
>
> cursors' xdata/ydata/zdata properties...
>
> is that what you want?
>
> % let's see what happens
> sh(1)=subplot(2,1,1);
> ph{1}=plot(rand(10,1));
> sh(2)=subplot(2,1,2);
> ph{2}=plot(rand(20,2));
> title('not linked');
> pause;
> title('linked');
> lp=linkprop(cat(1,ph{:}),{'xdata','ydata'});
>
> % also, another way of controlling mous/pointer
> % is shown here
>
> % create a roboter
> import java.awt.*;
> import java.awt.event.*;
> rob=Robot;
> ss=get(0,'screensize')
> sy=fix(ss(4)/2)
> for i=1:ss(3)
> rob.mouseMove(i,sy);
> pause(.01);
> end
>
> % to see more roboter options
> methods(rob);
>
> just a few thoughts
> us
Thanks us and Yair for your solutions. While not exactly what I was
looking for, I did learn a couple of new tricks :)
I should have been more specific. I am using the data cursor obtained
by executing 'datacursormode on' command to display the local pixel
info in my image. I have two of those cursors in two windows, and when
the user moves one of them, I want to update the other one too to
point to the same (x,y) coordinate.
Here is what I am trying (execute this in the command window):
figure; hp1 = plot(rand(10,1)); dcm1 = datacursormode;
figure; hp2 = plot(rand(10,1)); dcm2 = datacursormode;
Now if you click in the plot windows, you get a data tip showing the
(x,y) coordinate of the current point. The current coordinates can be
obtained by info_struct = getCursorInfo(dcm1). info_struct.Position
field contains the current position. Is there a way to update the
position of the datacursor dcm2?
Thanks
Subject: How to set the position of the data cursor programmitcally
Anup Mantri <anup.mantri@gmail.com> wrote in message
<1187381655.019037.265610@57g2000hsv.googlegroups.com>...
> I should have been more specific. I am using the data
cursor obtained
> by executing 'datacursormode on' command to display the
local pixel
> info in my image. I have two of those cursors in two
windows, and when
> the user moves one of them, I want to update the other one
too to
> point to the same (x,y) coordinate.
>
> Here is what I am trying (execute this in the command window):
> figure; hp1 = plot(rand(10,1)); dcm1 = datacursormode;
> figure; hp2 = plot(rand(10,1)); dcm2 = datacursormode;
use the following syntax to use your own data presentation
function instead of Matlab's default:
set(dcm1,'UpdateFcn',{@myDataTipFcn,dcm2}); % similarly for
dcm2
Then, within myDataTipFcn you can update the other data-cursor.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.