Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fill3 NaN delimited polygon

Subject: fill3 NaN delimited polygon

From: Matthew Nelson

Date: 16 Aug, 2010 19:18:04

Message: 1 of 4

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

Subject: fill3 NaN delimited polygon

From: Sean

Date: 16 Aug, 2010 19:44:05

Message: 2 of 4

"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

Do you mean this?

idx = any([~isnan(x);~isnan(y)],1); %This is to not plot if either x or y has a nan
subplot(1,2,1),fill(x(idx),y(idx),'k');

If it isn't could you further elaborate on your problem? Do you want it to look like the second subplot?

Subject: fill3 NaN delimited polygon

From: Frédéric Bergeron

Date: 16 Aug, 2010 19:51:06

Message: 3 of 4

"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

Subject: fill3 NaN delimited polygon

From: Matthew Nelson

Date: 16 Aug, 2010 20:22:04

Message: 4 of 4

Thanks Sean! That was exactly what I was trying to do.

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i4c4e5$im0$1@fred.mathworks.com>...
> "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
>
> Do you mean this?
>
> idx = any([~isnan(x);~isnan(y)],1); %This is to not plot if either x or y has a nan
> subplot(1,2,1),fill(x(idx),y(idx),'k');
>
> If it isn't could you further elaborate on your problem? Do you want it to look like the second subplot?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us