MATLAB: ‘fill’ and ‘image’ incompatible

alphadatafillimage

This demonstrates my previous question(<http://www.mathworks.com/matlabcentral/answers/6749-graphic-ghost)>, now with real code.
There is a wrong behaviour when I mix 'fill' and 'image' on the same plot.
This is demonstrated by the following code.
clc
close all
clear all
axis([-5 200 -5 200]);
axis square;
hold on
for pos=120:200
a=fill([10 10 0 0]+pos/2,[10 0 0 10]+pos/2,'r');
b=image([pos pos+40],[pos pos+40],rand(40)*100,'AlphaData',0.5*ones(40));
drawnow
if ishandle(b)
delete(a);
delete(b);
end
end
In Matlab r2010b the random color image will disapear as soon as it touch the axis(plot border). I can see only a thin line on the edge of the image. If you comment the 'a=fill…' and 'delete(a)' lines, it will work as expected. I tried to generate a animated gif with this, but it showed another bug, that I had complained previously. If you look at http://geodac.di.ubi.pt/nuno/bug1.gif you will see the 'fill' moving without the 'image'. When I add the image, at http://geodac.di.ubi.pt/nuno/bug2.gif, everything freezes on the first position. That means frame = getframe(1); only gets the first frame after the image was inserted, and the transparency seems to have been applied to the entire image.
This bug only appears when 'AlphaData' is used. Opaque images work fine!

Best Answer

The problem generating the movie is a known issue, documented here: http://www.mathworks.com/support/bugreports/384622. It mentions Windows Vista, but it also seems to occur on Windows 7.
The original issue of the image not showing up correctly could be a bug. I would recommend contacting support about it.
In just playing around with your example, it looks like perhaps swapping the order in which the image and the fill are created could be a workaround. Compare this ...
axis([-5 200 -5 200]);
axis square;
hold on
pos=160;
a=fill([10 10 0 0]+pos/2,[10 0 0 10]+pos/2,'r');
b=image([pos pos+40],[pos pos+40],rand(40)*100,'AlphaData',0.5*ones(40));
...and this...
axis([-5 200 -5 200]);
axis square;
hold on
pos=160;
b=image([pos pos+40],[pos pos+40],rand(40)*100,'AlphaData',0.5*ones(40));
a=fill([10 10 0 0]+pos/2,[10 0 0 10]+pos/2,'r');