Use a function instead of a script, have a variable in your main function representing the position and update this in your callback, ensuring that your callback is a nested function so that it has access to the variables in the main function.
There are other ways to do it, personally I use classes, but for an example this would be the simplest.
e.g
function roiTool( )
fighandle =figure();
axshandle = axes('Parent',fighandle);
imshow('cameraman.tif','Parent',axshandle)
roi(1).handle = imrect(axshandle);
roi(2).handle = imellipse(axshandle);
roi(3).handle = impoly(axshandle);
positions = cell( 1, 3 );
for i =1:3
addNewPositionCallback(roi(i).handle,@(pos) getpos(pos,roi(i).handle,i));
end
function getpos(pos, handle, i)
positions{i} = getPosition(handle);
end
end
I haven't tested that code so can't guarantee it works, but it gives the general idea.
Best Answer