Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: [Q] CallBack Problem
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Paulo Alexandre Silva

Posts: 3
Registered: 12/7/04
[Q] CallBack Problem
Posted: Aug 30, 1996 5:33 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


I have this label in a figure :

Hmenu(2)=uimenu(Hmenu(1),'Label','Search Window'...
,'CallBack', ['OUT=cur;']);

The function CUR shows the coordenates of mouse and other information.

When I use the function CUR from MATLAB commmand windown no problem,
when I execute the label I can´t see the coordenates and CUR return
OUT=[].

I don´t understand where is the problem ????

----------------------------- CUR.M ---------------------------
function out=cur(arg)

%CUR Show x-y Coordinates Using Mouse.
% CUR places the x-y coordinates of the mouse in the
% lower left hand corner of the current 2-D figure window.
% When the mouse is clicked for the second time ,the coordinates are erased.
%
% XY=CUR returns XY=[x,y] coordinates displayed when mouse was clicked.
% Returns XY=[] if a key is pressed.

% Paulo da Silva
% 28-8-96

global XY_OUT_ XY_FIRST_

ni=nargin;
if ~ni, arg='i'; end
if arg(1)=='i'
XY_FIRST_=[];
XY_OUT_=[];
Hf=gcf;
if isempty(Hf), error('No Figure Available.'),end
Ha=gca;
if isempty(Ha), error('No Axes in Current Figure.'),end
if any(get(Ha,'view')~=[0 90]), error('Plot must be 2D'); end

Hu=uicontrol(Hf,'Style','text',...
'units','pixels',...
'Position',[1 1 280 15],...
'HorizontalAlignment','left')
set(Hf, 'Pointer','crossh',...
'WindowButtonMotionFcn','cur(''m'')',...
'Userdata',Hu)

figure(Hf) % bring figure forward

if nargout % must return x-y data
key=waitforbuttonpress; % pause until mouse is pressed
if key,
out=[]; % return empty if aborted
cur('e') % clean things up
else
XY_FIRST_=XY_OUT_; % get first point
key=waitforbuttonpress; % pause until mouse is pressed
if key,
out=[]; % return empty if aborted
cur('e') % clean things up
else
out=[XY_FIRST_; XY_OUT_]; % now that move is complete return points
cur('e');
end
return
end
return
end

elseif arg(1)=='m' % mouse is moving, return x,y coordinates
cp=get(gca,'CurrentPoint'); % get current mouse position
XY_OUT_=cp(1,1:2);
xystr=sprintf('[x=%.3g, y=%.3g, xdim=%.3g, ydim=%.3g]',2*XY_OUT_,2*(XY_OUT_-XY_FIRST_));
Hu=get(gcf,'Userdata')
set(Hu,'String',xystr) % put x-y coordinates in text box

elseif arg(1)=='e' % mouse click occurred, clean things up
delete(get(gcf,'Userdata')) % delete text box
set(gcf,'Pointer','arrow',...
'WindowButtonMotionFcn','',...
'WindowButtonDownFcn','',...
'Userdata',[]) % clean up figure
set(gca,'Userdata',[]) % clear xy data
end



--
---------------------------------------------------------------------------------

/"\|/"\|/"\|/"\ Paulo Alexandre Ferreira da Silva <=> l38208@alfa.ist.utl.pt
< P | A | F | S >
\_/|\_/|\_/|\_/ Technical Superior Institute of Lisbon
/ \ / \ / \ / \ Electronics & Computers Engeneering
" ~ " ~ " ~ " ~ "
---------------------------------------------------------------------------------





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.