Scatte plot to contour plot xyz data.

조회 수: 103 (최근 30일)
Quinn Coughlin
Quinn Coughlin 2021년 3월 15일
댓글: Christopher McCausland 2021년 3월 16일
Hi I have a matrix called Total that is 3x100, the first column is the x value, the second column is the y value and the last column is the z value. When I input this matrix into a scatter plot I get a scatterplot with 3 paralell lines which is correct as I am mapping metal beams underneath concreate and the z value is the electrmagnetic value of the bar, how can I turn this graph into a contourf plot or a color plot.
Thanks

답변 (2개)

Star Strider
Star Strider 2021년 3월 15일
Several MATLAB plot types require the ‘Z’ argument to be a matrix.
One way of creating it is to interpolate it, and one way of doing that is this example where ‘x’, ‘y’ and ‘z’ are the original vectors:
N = 50; % Number Of Points Desired
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(x, y, z, X, Y);
figure
contourf(X, Y, Z)
axis('equal')
Experiment with it with your data.

Christopher McCausland
Christopher McCausland 2021년 3월 15일
Hi,
Have you tried Contour3 for three dimentional contour plots? You should be able to plot a secondary graph from this.
contour3(X,Y,Z);
Kind regards,
Christopher
  댓글 수: 2
Quinn Coughlin
Quinn Coughlin 2021년 3월 15일
Hi Christopher
Thanks for getting back to me, I am trying to get a 2d graph of the data. Also I get a error saying that Z needs to be a 2x2 matrix, how can I fix this?
Thanks Quinn
Christopher McCausland
Christopher McCausland 2021년 3월 16일
@Quinn Coughlin My appologies, I misunderstood what you were asking for. @Star Strider has a very good description below! Another way to interpolate is with cubic splines which would be a little smoother however I would say its probably overkill for this.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by