contour plot of cloud of points [closed]

I have a cloud of points scattered in a rectangle and some data in this points, a bit like this $$x(:)=[x(1), x(2), ..., x(N)] \\ y(:)=[y(1), y(2), ..., y(N)] \\ u(:)=[u(1), u(2), ..., u(N)]$$ Here, I am looking for plotting a contour of the $$u$$ data on matlab. I tried several function on matlab; contour, contourf, contourc,... etc but in vain.

Any help please

2 Answers

The only way I know of to visualise such data is to first triangulate it. Matlab can do the triangulation. See the Matlab functions 'delaunay', 'trisurf', 'pdecont'. This works if the domain is convex. If not then you need to construct the triangulation by accounting for the domain boundaries. Maybe Matlab has methods to do this, I am not very much familiar with Matlab. You may also want to look at Shewchuk's Triangle program https://www.cs.cmu.edu/~quake/triangle.html which may help in case of non-convex domains.

Also see this post: Plot a surface from data sets in MATLAB

• The domain is convex. I tried the delaunay method, indeed. But it appears that the results are biased as long a it is an interpolation. is there any way to keep the exact values and plot them without interpolate? – Amine HANINI Jan 14 '20 at 20:41
• stackoverflow.com/q/59706804/5837734 please check the edited post in stackoverflow – Amine HANINI Jan 14 '20 at 21:38
• There is no interpolation error at the triangle vertices since the value is given there. Looking at your pictures, it looks like domain is not convex and you are getting those thin triangles. – cfdlab Jan 15 '20 at 8:31

In essence, what you want to do is interpolate data: You want to find a function $$U(x,y)$$ so that $$U(x_i,y_i)=u_i$$. This is then the function for which you'd like to do draw isocontours.

You should take a look at books on numerical methods and search for "two-dimensional interpolation". Among the methods you will find is to triangulate your points $$(x_i,y_i)$$ to form a mesh, on which you can then define $$U(x,y)$$ as a piecewise linear function. But I think a better approach -- unless your data is pretty evenly distributed -- is to use something like the Radial Basis Function (RBF) method.