Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: [Q] CallBack Problem
Replies: 0

 Search Thread: Advanced Search

 Paulo Alexandre Silva Posts: 3 Registered: 12/7/04
[Q] CallBack Problem
Posted: Aug 30, 1996 5:33 AM
 Plain Text 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
" ~ " ~ " ~ " ~ "
---------------------------------------------------------------------------------

© The Math Forum at NCTM 1994-2018. All Rights Reserved.