how to get the contour/shape of a representation in 2D?
Ältere Kommentare anzeigen
Hello! I have two sets of x and y data that I plot. Following the representation, the result is the following figure.

When I use the plot function for representation, to connect the dots, I get the following result:

But I would be interested in the points being connected so as to create a closed surface, such as a contour or a shape, like in the following image:

Is there a matlab function that could help me in this regard?
I also attach the data in .mat.
Thank you very much!
!! Edit:
I just find out about the matlab function boundary and i use it and obtain the results from the figure. But I am not satisfied with the result because I would like all the points to be connected in one representation. And here, two point are left behind.

Akzeptierte Antwort
Weitere Antworten (2)
Torsten
am 16 Mär. 2022
0 Stimmen
[k,~] = convhull(P);
plot(P(k,1),P(k,2))
with P being your points as an nx2 matrix.
2 Kommentare
Jessie Bessel
am 16 Mär. 2022
If you order the points in x,y arrays in the sequel they should be connected by lines, MATLAB will plot correctly, e.g.
x = [1 2 4 1 ]
y = [3 6 8 3 ]
plot(x,y)
Point #8 is close to the previous one and you have to break it into 2 parts and combine them manually.
Of course, if the code is used for another combination of points, it does not work.
load('x.mat');
load('y.mat');
x1 = x(1:9); y1 = y(1:9); % Separate at point #8 & #9
x2 = x(8:end); y2 = y(8:end);
k1 = boundary(x1',y1');
k2 = boundary(x2',y2');
pgon1 = polyshape(x1(k1),y1(k1));
pgon2 = polyshape(x2(k2),y2(k2));
pgon = union(pgon1,pgon2); % Union 2 polygons
plot(pgon);
hold on
plot(x,y,'r*')
Kategorien
Mehr zu Contour Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


