help me in using "interp2"

3 ビュー (過去 30 日間)
Mahmood
Mahmood 2015 年 9 月 19 日
コメント済み: Mahmood 2015 年 9 月 20 日
I want to expand my matrix using interpolation. I followed the instructions but it shows some errors:
clc
clear
rw=0.10795;
n = linspace(-pi,pi,30);
m = linspace(rw,2.5,30);
[theta,r] = meshgrid(n,m);
[X,Y] = pol2cart(theta,r);
V = peaks(X,Y);
figure
surf(X,Y,V)
title('Original Sampling');
nn = linspace(-pi,pi,360);
mm = linspace(rw,2.5,200);
[thetaaa,rrr] = meshgrid(nn,mm);
[Xq,Yq] = pol2cart(thetaaa,rrr);
Vq = interp2(X,Y,V,Xq,Yq,'cubic');
figure
surf(Xq,Yq,Vq);
title('Cubic Interpolation Over Finer Grid');

採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 19 日
your input grid, X, Y, must be cuboid.
Leave your inputs the same, but change the command from interp2 to griddata (with the same arguments).
Also you will want to add 'edgecolor','none' to the surf() call.
griddata() is going to tell you that duplicate values have been averaged. I suspect -pi and +pi map to the same point with pol2cart. If you were to linspace() with 31 points and then delete the last then the overlap should disappear.
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 9 月 19 日
編集済み: Walter Roberson 2015 年 9 月 19 日
rw=0.10795;
n = linspace(-pi,pi,31);
n(1) = [];
m = linspace(rw,2.5,30);
[theta,r] = meshgrid(n,m);
[X,Y] = pol2cart(theta,r);
V = peaks(X,Y);
figure
surf(X,Y,V, 'edgecolor','none')
title('Original Sampling');
nn = linspace(-pi,pi,360);
mm = linspace(rw,2.5,200);
[thetaaa,rrr] = meshgrid(nn,mm);
[Xq,Yq] = pol2cart(thetaaa,rrr);
Vq = griddata(X,Y,V,Xq,Yq,'cubic');
figure
surf(Xq,Yq,Vq, 'edgecolor', 'none');
title('Cubic Interpolation Over Finer Grid');
Mahmood
Mahmood 2015 年 9 月 20 日
Thanks a lot for your help. I really appreciate that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by