interpn griddata difference?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi,
What are the differences between interpn and griddata?
Thank you.
채택된 답변
Bjorn Gustavsson
2020년 4월 14일
0 개 추천
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)?
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
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에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
