Using griddata on an unstructured grid
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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.
採用された回答
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?
Stephen23
2016 年 9 月 6 日
"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 :)
Meghan
2016 年 9 月 6 日
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?
Steven Lord
2016 年 9 月 6 日
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 :)
Meghan
2016 年 9 月 7 日
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 についてさらに検索
参考
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)
