How to plot 2d & 3d contour with xy coordinates with corresponding z values?

7 views (last 30 days)
I am modelling an embankment data at the moment. I want to plot a contour graph from 3 columns data that would look similar to the one shown below. Turned out the plot had some unnecessary linkages and the mesh was too dense that I could not really see what was happening at the top of the embankment. The codes under are the ones I tried in Matlab. How can I make a nice 2d or 3d contour graph that I want? As an example, one of my dataset is attached below. Thank you so much.
x = trial(:,1) ; y = trial(:,2) ; z = trial(:,3) ;
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;

Accepted Answer

jonas on 19 Jul 2020
If you had the geometry saved, e.g. as .stl file, then you could just pass some constraints to the delunayTriangulation. However, a small problem is that your edges are not straight, so it becomes difficult to define cornerpoints.
Here's another method you could try:
xyz = readmatrix('mesh data.xlsx');
[x,y,z] = deal(xyz(:,1),xyz(:,2),xyz(:,3))
% alphashape to get tight boundary without holes
shp = alphaShape(x,y,'holethreshold',1e5);
% plot edges
edges = boundaryFacets(shp);
plot(x(edges),y(edges),'k','linewidth',2);hold on
%get connectivity
tri = alphaTriangulation(shp);
t = trisurf(tri,x,y,z);
t.EdgeColor = 'none'

More Answers (0)




Community Treasure Hunt

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

Start Hunting!