Does anyone know how can I have a 2D-contour plot of some given data points?
I have the coordinates inside two vectors x and y. The problem is there is no analyctical function relating the height z, to the coordinates.
I have a seperate vector which has the values of z corrospondig to each (x,y) pair.
I would appreciate if you could help me with this.
Thanks in advance!

 채택된 답변

Star Strider
Star Strider 2019년 8월 15일

1 개 추천

You might find the griddata function useful. It takes random (x,y) values and interpolates gridded z-matrices from them that contour and contourf can use.

댓글 수: 4

Thanks for your response.
The problem is still that I do not know how the relate the Z vector to the X and Y. Check out the following example:
x=1:8;
y=x;
[X,Y]=meshgrid(x,y)
Z=sin(X)+cos(Y)%This is an example of analyctical function for Z.
%However, I miss this function. Since I only have a vector for Z with stored data
Star Strider
Star Strider 2019년 8월 16일
My pleasure.
You do not need a function to create ‘Z’, since in your situation ‘Z’ are data you collect. You can create a contour plot of ‘Z’ when you have it as a matrix. If your data are already gridded, you only have to use the reshape function to create matrices from your vectors. Otherwise, you need to use the griddata function to create the ‘Z’ matrix.
If you want to fit a function to your data, that is possible. However, you first need a function that you are reasonably certain describes your data.
Parham Ebrahimi
Parham Ebrahimi 2019년 8월 16일
You were right. I tried with reshape and it worked. Now I will interpolate to generate more data in the contour.
Thanks!
Star Strider
Star Strider 2019년 8월 16일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

질문:

2019년 8월 15일

댓글:

2019년 8월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by