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

New contributor
Amine HANINI is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.


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

  • $\begingroup$ 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? $\endgroup$ – Amine HANINI Jan 14 at 20:41
  • $\begingroup$ stackoverflow.com/q/59706804/5837734 please check the edited post in stackoverflow $\endgroup$ – Amine HANINI Jan 14 at 21:38
  • $\begingroup$ 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. $\endgroup$ – cfdlab Jan 15 at 8:31

Your Answer

Amine HANINI is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.