Drawing and filling different polygons at the same time in MATLAB

Posted by Hossein on Stack Overflow See other posts from Stack Overflow or by Hossein
Published on 2010-05-31T16:44:42Z Indexed on 2010/05/31 17:13 UTC
Read the original article Hit count: 245

Filed under:
|
|

Hi,I have the code below. It load a CSV file into memory. This file contains the coordinates for different polygons.Each row of this file has X,Y coordinates and a string which tells that to which polygon this datapoint belongs. for example a polygone named "Poly1" with 100 data points has 100 rows in this file like :

Poly1,X1,Y1
Poly1,X2,Y2
...
Poly1,X100,Y100
Poly2,X1,Y1
.....

The index.csv file has the number of datapoint(number of rows) for each polygon in file Polygons.csv. These details are not important. The thing is: I can successfully extract the datapoints for each polygon using the code below. However, When I plot the lines of different polygons are connected to each other and the plot looks crappy. I need the polygons to be separated(they are connected and overlapping the some areas though). I thought by using "fill" I can actually see them better. But "fill" just filles every polygon that it can find and that is not desirable. I only want to fill inside the polygons. Can someone help me? I can also send you my datapoint if necessary, they are less than 200Kb. Thanks

 
[coordinates,routeNames,polygonData] = xlsread('Polygons.csv');
index = dlmread('Index.csv');
firstPointer = 0
lastPointer = index(1)
for Counter=2:size(index)
    firstPointer = firstPointer + index(Counter) + 1
    hold on
    plot(coordinates(firstPointer:lastPointer,2),coordinates(firstPointer:lastPointer,1),'r-')
    lastPointer = lastPointer + index(Counter)
end


© Stack Overflow or respective owner

Related posts about matlab

Related posts about plot