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?
0 个评论
回答(2 个)
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 个评论
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!