MATLAB: In App designer, what’s the difference bewteen app.UIAxes and “a valid Axes object”

app designerdrawrectangleMATLAB

I'm trying to write a program using App Designer that will read a PNG file, display it on a app.UIAxes, and then draw a rectangle on the image. The code looks like this:
39 ax=app.UIAxes;
40 image(ax,app.data);
41 rr=drawrectangle(ax,'Position',[100,157,11,54]);
Line 40 displays the image on the correct axes. Line 41 throws the errors below.
So what's the difference bewteen app.UIAxes (above) and "a valid Axes object" (below)?
Error using images.roi.internal.ROI/parseInputs
ROI parent must be a valid Axes object.
Error in images.roi.Rectangle
Error in drawrectangle (line 178)
h = images.roi.Rectangle(varargin{:});
Error in app1/ShowAnimation (line 41)
rr=drawrectangle(ax,'Position',[100,157,11,54]);
If I pop up a separate figure, similar code works fine.

Best Answer

I can't explain the error, but if you are looking for a workaround, use rectangle instead of drawrectangle.