MATLAB: How to get the draggable rectangles using FINDOBJ in MATLAB 7.11 (R2010b)

findobjimrectMATLAB

I want to get the draggable rectangles by using FINDOBJ function:
figure
imrect(gca, [10 10 50 50]);
databox=findobj(gca, 'Type', 'imrect');
But it does not work as the variable databox returns an empty matrix.

Best Answer

The issue is that with FINDOBJ, there is no value called 'imrect' in the 'Type' property. To find all the draggable rectangles in the figure, please replace following code in your program:
databox = findobj(gca, 'Type', 'imrect');
with:
databox = findobj(gca, 'Type', 'hggroup', 'Tag', 'imrect');
As you can see, the draggable rectangle is a group object.