Convert from XYZ surface plot to just Z surface plot

I have a data set consisting of xcoord, ycoord, and density in vectors, exported from Fluent. I would like to be able to view the data as an m x n matrix, rather than as a surface plot, surf(X,Y,Z), so that I can access specific elements of that matrix directly. (i.e., I would like to be able to say density(ii,jj) = ....). I've tried many methods for doing this, and all have resulted in a skewed looking plot.

 采纳的回答

You did not say what you have tried, and what did not work.
Consider:
Z = randn(100);
figure
surf(Z)
view(0,90)
That produces a (100x100) matrix, and the view call lets you look at it from the top, rather than from the side.

4 个评论

I know about view, but I don't need to simply see the resulting surface from a top view. I need to be able to access specific points on the matrix. For instance, I need to be able to access Density(ii,jj), and I cannot do that using the x,y,and z coordinate version of surf, unless there is a way I don't know about. Is there a way to say Z(x(ii,jj),y(ii,jj)) where I can actually return the index of x(ii,jj) and y(ii,jj)?
I've tried using scatteredInterpolant, making a new meshgrid with integer coordinates, sorting and reshaping vectors, and probably a few more I'm forgetting.
The problem is that the plot from surf(Z) does not match the plot of surf(X,Y,Z), and I need something to make it to where it does.
Walter Roberson in his comment mentioned the griddata (link) function as a way to easily access any ‘Z’ values by their ‘X’ and ‘Y’ values. Unless you have a function that accurately describes your data (so you can use it to calculate ‘Z’ from the others), I would begin with griddata. You can probably create an anonymous function using it if you need to.
I must have overlooked that the first time, but griddata did the trick! Thank you both so much :)

请先登录,再进行评论。

更多回答(0 个)

类别

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by