putting function values in meshgrid format

I have coordinate vectors X and Y and corresponding vector of function values Z. Points (Xi,Yi) are distributed irregularly on plane. I'm trying to convert these points to a regular mesh with constant spacing, calculate corresponding values Z and plot them using surf. What is the best way to do it in matlab? I was looking at interp2, but it requires data in meshgrid format.
Thanks!

 채택된 답변

Star Strider
Star Strider 2018년 5월 2일

1 개 추천

Your data may already be gridded. I would first plot it using stem3, for example:
figure
stem3(X, Y, Z)
grid on
If it appears that the data are regularly spaced with respect to ‘X’ and ‘Y’, then you only need to use reshape to create matrices from your vectors. If you then want to interpolate it, the griddata function may be easiest to use.

댓글 수: 4

skuznet
skuznet 2018년 5월 2일
편집: skuznet 2018년 5월 2일
Thanks! Looks like I'm asking incorrect question. I've corrected it. The data is actually already grided, but the mesh is irregular, I'm trying to put it on a regular mesh, with constant spacing.
Star Strider
Star Strider 2018년 5월 2일
My pleasure.
You likely need to use reshape to create matrices from your vector data. Then you can use interp2, griddata, or other interpolation options with it.
skuznet
skuznet 2018년 5월 2일
Thanks a lot! The following worked for me:
Zinter = scatteredInterpolant(Xs,Ys,Z) %defines interpolant for scattered data and allows to calculate values of z for any point
Star Strider
Star Strider 2018년 5월 2일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

질문:

2018년 5월 2일

댓글:

2018년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by