MATLAB: Ginput is turning off mouse cursor

ginput

Hi, I am not a MATLAB programmer but have a lot of experience with C and Basic. Therefore, for my sins, I have been asked to look at a problem one of our researchers is having with some code written a long time ago which works fine in version 7.1.0.246 but is giving a problem in MATLAB version 7.10.0.499
There is a GUI as part of the program that shows the mouse cursor when it is initially displayed, ie the mouse can be moved around the screen and is always visible.
On clicking a button to execute a function, in the earlier version of MATLAB, the mouse cursor remains visible inside this GUI along with the ginput crosshairs. However, in the later version, the mouse cursor disappears and all that is visible are the crosshairs as the mouse is moved around.
I have tracked down the point in the code where the cursor becomes invisible and it is when this function is executed. I have copied it below.
Can anyone tell me why this should be happening and, even better, how I can make the cursor remain visible using the later version of MATLAB, please.
The earlier version of MATLAB is running under Windows XP. The later version is on both an XP and Windows 7 machine and both display this problem.
Very many thanks,
Peter
% — Executes on button press in markEnclosuresPushbutton. function markEnclosuresPushbutton_Callback(hObject, eventdata, handles)
px = ones( 1, 16 ); py = ones( 1, 16 );
for encCnt = 1 : 16
[ px( encCnt ), py( encCnt ) ] = ginput(1);
hold on;
plot( px( encCnt ), py( encCnt ), 'r.' )
h = text( px( encCnt ) + 2, py( encCnt ) -2, num2str( encCnt ) );
set(h,'color','r');
drawnow;
end
handles.data.spec.encPx = px;
handles.data.spec.encPy = py;
set( handles.startPushbutton, 'enable', 'on' );
guidata( hObject, handles );

Best Answer

Does the code by any chance rely on window events such as buttondownfcn, buttonmotionfcn, etc? ginput() has the annoying behaviour of overwriting these function (so it can show the cross-hairs) but not putting them back when it's done. Try encasing your loop in the following:
% Collect old fig handle functions overwritten by ginput
fcnNames = {'WindowButtonDownFcn','WindowButtonMotionFcn'};
fcnVals = get(gcf,fcnNames);
oldFcnNameValPairs = cat(1, fcnNames, fcnVals);
... % Your loop here %
set(gcf, oldFcnNameValPairs{:}) % Restore the original figure functions
Now, admittedly I would expect that if this were the problem it wouldn't only appear in the later MATLAB version, and the single calls to ginput() should at least return your original mouse cursor, but you might get lucky.