"Matthew Nelson" <nelsonm@lanl.gov.remove.this> wrote in message <i4c2tc$ain$1@fred.mathworks.com>...
> Does anyone know how to get Matlab to fill in a polygon with holes in it? Basically I would like the same functionality of fill and fill3 to work with a NaN delimited polygon. Fill and fill3 are able to plot the edges just fine but are unable to color the faces. For example:
>
> x=[5,17,15,5,5,NaN,8,10,13,7,8,NaN];
> y=[5,5,15,15,5,NaN,8,6,14,13,8,NaN];
> x1=x(1:5);
> y1=y(1:5);
> subplot(1,2,1),fill(x,y,'k');
> axis equal;
> subplot(1,2,2),fill(x1,y1,'k');
> axis equal;
>
> I would like to be able to do this with an arbitrary number of holes. Thanks in advance for any help you can give.
>
> Matt
Hey,
I could get a superposition of plots, but the holes are not really «holes» because they are white patches, and there is still a black patch underneath. Depending of your application, it could be an acceptable answer...
x=[5,17,15, 5,5,NaN,8,10,13, 7,8,NaN,12,12,14,14,12,nan];
y=[5,5, 15,15,5,NaN,8, 6,14,13,8,NaN,6, 7, 7, 6, 6,nan];
idx=find(isnan(x));
figure;
clear h;
h.all=fill(x(1:idx(1)1),y(1:idx(1)1),'k'); hold on;
for n=1:length(idx)1
h.(['hole' num2str(n)])=fill(x(idx(n)+1:idx(n+1)1),y(idx(n)+1:idx(n+1)1),'w');
end
Fred
