Reshape data vector for a surf plot over a non-rectangular domain
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Bjorn Gustavsson
am 25 Nov. 2020
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 Kommentare
Bjorn Gustavsson
am 25 Nov. 2020
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
am 25 Nov. 2020
Bearbeitet: Bruno Luong
am 25 Nov. 2020
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 Kommentare
Bruno Luong
am 25 Nov. 2020
F = scatteredInterpolant(X,Y,Z,'linear','nearest');
z = F(x,y);
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

