interpn griddata difference?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Hi,
What are the differences between interpn and griddata?
Thank you.
採用された回答
Bjorn Gustavsson
2020 年 4 月 14 日
The interpn function requires input data on a plaid grid, i.e. as you would produce with meshgrid, or perhaps ndgrid, while griddata (and scatteredInterpolant and TriScatteredInterp) expects input data on irregular grids. GRIDDATA expects the inputs as 1-D vectors. See the help and documentation for the respective functions, there you should find "minimal" illustrating examples to look at.
HTH
5 件のコメント
Tahariet Sharon
2020 年 4 月 15 日
Thanks. Do I understand correctly that interpn can be used also for the cases where griddata is used (for irregular grids)?
Bjorn Gustavsson
2020 年 4 月 15 日
No. interpn can only handle grids as produced by ndgrid (I recalled that it could also handle grids as produced by meshgrid, but that was not the case for the matlab-version on my laptop, this might have been the case for "very" old matlab-versions.). That means that the grids for interpn might have step-sizes that varies along each separate dimension:
[x,y,z] = ndgrid([0 1 2],[-3 -1 0 1 3],[0 1 2 4 8]);
[xi,yi,zi] = meshgrid(0:.1:2,-3:.1:3,0:.1:8);
I = exp(-(x-1).^2-(y-1).^2-(z-3).^2);
Ii = interpn(x,y,z,I,xi,yi,zi);
slice(xi,yi,zi,Ii,1,1,3),shading flat
That grid is still "plaid" - Each "cell" [dx,dy,dz] would still be cube-ish (dont remember name of that geometric shape in English). griddata and the other triangulation-based interpolation-functions handle interpolation of properly irregularly sampled data:
xR = 1 + randn(75,1);
yR = 2*randn(75,1);
zR = 4 + 2.5*randn(75,1);
Ir = exp(-(xR-1).^2-(yR-1).^2-(zR-3).^2);
Igd = xi;
Igd(:) = griddatan([xR,yR,zR],Ir,[xi(:),yi(:),zi(:)]);
slice(xi,yi,zi,Igd,1,1,3),shading flat
hold on
scatter3(xR,yR,zR,32,log(Ir),'filled')
That type of data interpn cannot handle.
HTH
Tahariet Sharon
2020 年 4 月 16 日
Actually, when I run the example above I get:
Warning: Query data is in MESHGRID format, NDGRID format will yield better performance.
Convert your query data (Xq, Yq, Zq) as follows:
F = griddedInterpolant(. . .);
P = [2 1 3];
Xq = permute(Xq, P);
Yq = permute(Yq, P);
Zq = permute(Zq, P);
Vq = F(Xq,Yq,Zq);
Bjorn Gustavsson
2020 年 4 月 16 日
Yeah, that might very well be a slight performance-booster (check such things with the profiler-functionality if you need speed-ups...). I was too lazy to do that since my example was rather small and I only wanted to plot the data with the slice function, which used to expect the data to be in the meshgrid format.
The one advice when it comes to this meshgrid/ndgrid option is DOCUMENT YOUR CHOICE CLEARLY (and I'm shouting mainly for me to remember this...), the speed-up should be rather minor - typically, I think I've lost more time hunting down where I've done which choice than I've gained or lost due to this performance difference.
HTH
Tahariet Sharon
2020 年 4 月 17 日
Thanks for all your help. You have been really helpful! Stay safe.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
参考
2020 年 4 月 14 日
2020 年 4 月 17 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
