Using griddata on an unstructured grid
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello
This is probably a very silly question but I can't really wrap my head around griddata. I've used it previously but it was a lot more straight forward then!
So right now I have one set of coordinates (x,y) which represent and unstructured grid. I also have another set of coordinates with represent the centre of each of those triangles in the unstructured grid. I have a velocity value for each of the points within the triangle. What I need to do is to interpolate the data from the centre of the triangle to the different node points, which would be my first set of coordinates. I've been trying to use griddata but keep getting error messages.
I'm not sure if I've explained myself very well but I've attached my code to this question so hopefully that will be clearer.
채택된 답변
0 개 추천
As your data is unstructured, you can consider this data as scattered data. Why don't you use scatteredInterpolant? I have used this quite lot of times for unstructured grid and it worked perfectly for me.
More on:
댓글 수: 10
Meghan
2016년 9월 6일
Hi Siva
I had considered using scatteredInterpolant, but when I tried it gave me an error that my sample values must be a double array. I've never had to try to change an array from single to double so I'm not really too sure how to do it. And googling the answer didn't really help me much. Do you have any suggestions?
KSSV
2016년 9월 6일
Can you attach your data?
"I've never had to try to change an array from single to double so I'm not really too sure how to do it."
doubleData = double(singleData)
Meghan
2016년 9월 6일
I'm actually not able to.
But OSRef_nodeX & OSRef_nodeY are 46878x1 double matrices, while u is a 79244x1 single matrix.
I know this makes everything a lot more complicated that I can't share it, so I understand if you can't help.
Thank you :)
Thank you Stephen, that did it! However now I'm getting the error:
Error using scatteredInterpolant
The number of data point locations should equal the number of data point values.
KSSV
2016년 9월 6일
Your x,y, and z values shall be of same dimension.....
But they're not. This is why I need to interpolate. I have 46878 nodal points. This gives me 79244 points in the centre of the triangles because I have more triangles than nodes. What I need to do is interpolate the velocity data from the centre of the triangle (79244 points) to the nodes of the triangle (46878 points).
Right now I have
% Interpolating from the triangle to the nodes
XY=longlat2os(mesh.uvnode(:,1),mesh.uvnode(:,2),'degrees','northeast'); %coordinates for all trinodes
u1=A.FVCOM1.u(1,1,:); u=squeeze(double(a));
XY1=griddata(OSRef_nodeX,OSRef_nodeY,u,XY(:,1),XY(:,2),'linear');
Which looks like XY1=griddata(46878x1 double, 46878x1 double, 79244x1 single, 79244x1 double, 79244x1 double, 'linear');
And I'm getting the error:
Error using griddata (line 109)
X and Y must be same length as Z or the lengths of X and Y must match the size of Z.
So I'm wondering if what I want is even possible?
Construct your scatteredInterpolant using the coordinates of the centers of the triangles and the value at each of those centers of the variable you want to interpolate. Then evaluate the scatteredInterpolant using the coordinates of the vertices of the triangles.
In the 2-D Interpolation example on the documentation page I linked above, x and y will be the coordinates of the triangle centers. v will be the values of the data you're trying to interpolate at each of those centers. xq and yq will be the coordinates of the triangle vertices. vq will be the interpolated values of the data at each of those vertices. While this example uses mesh and plot3 to plot the data, you may find trisurf or trimesh (with the interpolated vq values serving as the Z coordinates of each of the points) better suited to display your triangular "grid".
Meghan
2016년 9월 6일
You are a life saver! I've been trying to figure this out all day!
Thanks so much :)
Steven I wonder if you can help me. That method above does what I want when the v value is 79244x1. Can I use the same method if v is 79244x24x10? I've been fiddling with it this morning and haven't had much luck. I keep getting the error
Error using scatteredInterpolant
Input data point values have invalid dimension. The data must be specified in column-vector format.
I've introduced a z matrix so that the input is
XY3=scatteredInterpolant(uvX,uvY,mesh.uvdepth,u3,'linear');
Not sure if that is correct? Any advice?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
