MATLAB: Update the ROI with drawrectangle change

computer visiondrawrectanglefigureguiMATLAB

Hi,
I'm trying to draw a shape (rectangle, circle etc.) to determine region of interest (ROI) in an image. When I use the drawrectangle function, I can get the corners of the first instance that the rectangle is drawn, however when I edit the rectangle on the figure (change size/position), it does not update the roi variable. How can I update the roi variable when the rectangle is altered in a script?
Code I use is below and I use R20109a;
temp = snapshot(cam1);
imshow(temp);
rect = drawrectangle;
roi = rect.Position;

Best Answer

For anyone who is wondering how to solve this issue; here is my solution that works;
This is the main code
imshow(snapshot(camL));
rect = drawrectangle;
roiL = rect.Position;
addlistener(rect,'ROIMoved',@(src, evt) roiChange(src,evt,'roiL'));
And the function
function roi = roiChange(src,evt,roi)
assignin('base',roi,evt.CurrentPosition);
end
Thanks for all the help.