Reshape data vector for a surf plot over a non-rectangular domain

11 次查看(过去 30 天)
I have a number of points in the x-y-plane defined by the vectors X and Y, and associated functions values for those points in the vector Z. I need to make a surf plot of the data in Z over the domain defined by X and Y. The values in Z cannot be evaluated from an analytical expression, thus I cannot use meshgrid in the traditional way. How do I reshape the data in Z in order to fit the required input of the surf function?
Also, I would like the surf plot to only cover the geomtry in the x-y-plane defined by X and Y. I have attached a patch plot of the data over a diamond-shaped geometry. How do I ensure that the surf plot is generated over the diamond-shaped domain only?

回答(2 个)

Bjorn Gustavsson
Bjorn Gustavsson 2020-11-25
If you have your x, y and z data in 1-D arrays you can use trisurf see the help and documentation for that function for usage. If you want this type of projection just set the view to be from above after the call to trisurf: view(0,90).
HTH
  2 个评论
David Hoffmeyer
David Hoffmeyer 2020-11-25
Thank you, Bjorn. Though the edges are not quite as sharp as desired due to the triangulation used by trisurf.
Bjorn Gustavsson
Bjorn Gustavsson 2020-11-25
For that, it depends on how you want the plot to look, you might get away with cleaning away the large blue and light-blue triangles by maually removing them from the triangulation - I've never bothered doing that kind of thing, so have no solutions except suggesting maual inspection of the tri structure.

请先登录,再进行评论。


Bruno Luong
Bruno Luong 2020-11-25
编辑:Bruno Luong 2020-11-25
A diamond shape is bijective mapped from/to a rectangular shape, thus meshgrid/ndgrid combined with surf are still applicable.
n = 100;
s=linspace(0,1,n);
t=linspace(0,1,n);
[s,t] = meshgrid(s,t);
[sc,tc] = meshgrid([0 1],[0 1]);
x = interp2(sc,tc,[0 4; -4 0], s, t);
y = interp2(sc,tc,[-2 0; 0 5], s, t);
z = peaks(n); % scattered interpolation with nearest extrapolation from your X,Y,Z data is needed to get z
surf(x,y,z,'EdgeColor','none');
view(2)
axis equal
colormap(jet)
The advantage compared to trisurf proposed by Bjorn is you can make sure the boundary of the shape are straight.
  3 个评论
David Hoffmeyer
David Hoffmeyer 2020-11-25
Something is not right with the scatteredInterpolant function. Also, As far as I can see, you are manually defining the diamond geometry, so can this work on arbitrary geometries?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by