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

1 view (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.
trial=meshdata{:,:}
x = trial(:,1) ; y = trial(:,2) ; z = trial(:,3) ;
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;
figure
trisurf(tri,x,y,z)

Accepted Answer

jonas
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'
view(2)

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!