How do I create a polygon from coordinates?

7 views (last 30 days)
I have a black image and with the program I have so far I'm plotting coordinates from a txt file on the image. What I wanna do is modify the image by creating lines between the coordinates and make it look like a polygon. How can I do that?
[m, n] = size(dataTxt);
o_str = imshow(foto,'Parent', handles.axes1);
for i = 1:n
[p, q] = size(dataTxt{i});
if (dataTxt{i}(p,1) == 1)
color_display= 'ro';
elseif (dataTxt{i}(p,1) == 2)
color_display= 'bo';
end
for j = 1:p
x = dataTxt{i}(j,1)
y = dataTxt{i}(j,2)
hold on; plot(x, y, color_display);
end
a = num2str(i);
text(dataTxt{i}(1,1), dataTxt{i}(1,2), a);
end

Answers (1)

Walter Roberson
Walter Roberson on 2 Jul 2015
if (dataTxt{i}(p,1) == 1)
color_display= 'ro-';
elseif (dataTxt{i}(p,1) == 2)
color_display= 'bo-';
end
x = dataTxt{i}(:,1)
y = dataTxt{i}(:,2)
plot(x, y, color_display);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!