matlab - MeshGrid for Triangle Elements -
i want build contourf
plot of aspect in plate. plate divided in triangle elements, have coordinates (x,y) of each knot of triangle.
so, how can make meshgrid
knots can make contourf
plot?? have coordinates of , have value of function z
in each knot. (i'm beginner in matlab, sorry "basic" question)
if goal visualise triangles there way that's simpler , more robust (see end of post).
if need generate contours need interpolate triangular mesh on grid. can use scatteredinterpolant
class (documentation here). takes x , y arguments or triangular vertices (knots), z values each 1 , creates 'function' can use evaluate other points. create grid, interpolate triangular mesh on grid , can use results countour plot.
the inputs scatteredinterpolanthave linear column vectors, need reshape them using the
(:)`notation.
so let's assume have triangular data this
x = [1 4; 8 9]; y = [2 3; 4 5]; z = [0.3 42; 16 8];
you work out upper , lower limits of range first
xlimits = minmax(x(:)); ylimits = minmax(y(:));
where (:) notation serves line elements of x in single column.
then can create meshgrid
spans range. need decide how fine grid should be.
spacing = 1; xqlinear = xlimits(1):spacing:xlimits(2); yqlinear = ylimits(1):spacing:ylimits(2);
where linspace makes vector of values starting @ first 1 (xlimits(1)
) , ending @ third 1 (xlimits(2)
) , separated spacing
. experiment , @ results, you'll see how works.
these 2 vectors specify grid positions in each dimension. make actual meshgrid
-style grid call meshgrid
on them
[xq, yq] = meshgrid(xqlinear, yqlinear);
this produce 2 matrices of points. xq
holds x-coordinates of every points in grid, arranged in same grid. yq
holds y-coordinates. 2 need go together. again experiment , @ results, you'll see how works.
then can put them interpolation:
f = scatteredinterpolant(x(:), y(:), z(:)); zq = f(xq, yq);
to interpolated values zq
@ each of grid points. can send data contourf
contourf(xq, yq, zq);
if contour blocky need make spacing
value smaller, create more points in interpolant. if have lots of data might cause memory issues, aware of that.
if goal view triangular mesh might find trimesh
want or, depending on how data represented, scatter
. these both produce 3d plots wireframes or point clouds though if need contours interpolation way go.
Comments
Post a Comment