Conversion polar to Cartesian by interpolation

24 次查看(过去 30 天)
Hi every one
I have a strange error in my code
I have convert the data from Cartesian to the polar as bellow:
Error using interp2>makegriddedinterp (line 237)
Input grid is not a valid MESHGRID.
Error in interp2 (line 136)
F = makegriddedinterp(X, Y, V, method,extrap);
can any body solve this problem?

回答(1 个)

Steven Lord
Steven Lord 2015-7-2
INTERP2 requires gridded data. The X and Y coordinate data you converted from polar is not gridded.
theta = (0:1/4:2)*pi;
rad = 0:5;
[T, R] = meshgrid(theta, rad);
[X, Y] = pol2cart(T, R);
Z = X.^2+Y.^2;
plot3(X, Y, Z, 'ko');
You may want to rotate that data to convince yourself that it's a bowl shape. To obtain the values of other points on the bowl, you will need to interpolate this using a tool that can interpolate scattered data:
[x2, y2] = meshgrid(-3:0.25:3);
S = scatteredInterpolant(X(:), Y(:), Z(:));
z2 = S(x2, y2);
hold on
plot3(x2, y2, z2, 'r+');
You should now see a "mesh" of + signs, like a piece of paper towel resting on the inner surface of the bowl.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by