How to extract values within a circular region from a griddata?
17 ビュー (過去 30 日間)
古いコメントを表示
I have a 2d matrix (100 x 100 size) obtained from the piece of code is as follows:
N = 100;
xv = linspace(min(CoordsX), max(CoordsX), N);
yv = linspace(min(CoordsY), max(CoordsY), N);
[X,Y] = ndgrid(xv, yv);
Data = griddata(CoordsX, CoordsY, Field, X, Y);
figure()
surf(X, Y, Data) % This make a surface plot of Data.
'Data' outputs a 100 x 100 matrix and then I plot a surface plot as it is in the code. Here I want to select a region with in a circle centered at xc, yc and radius 'r'. Then make another surface plot. How can I extract the vlaues from 'Data' those are within a circular region or radius 'r'?
Thank you
0 件のコメント
採用された回答
Bjorn Gustavsson
2022 年 6 月 23 日
You "simply" only ask for the values inside that circular region. You can do it at least two different ways:
N = 100;
xv = linspace(min(CoordsX), max(CoordsX), N);
yv = linspace(min(CoordsY), max(CoordsY), N);
[X,Y] = ndgrid(xv, yv);
Data = griddata(CoordsX, CoordsY, Field, X, Y);
figure()
subplot(2,2,1)
surf(X, Y, Data) % This make a surface plot of Data.
Ioutside = find((X(:)-xc).^2+(Y(:)-yc).^2>r);
Data(Ioutside) = nan;
surf(X, Y, Data) % This make a surface plot of Data inside the circular region.
phi360 = (0:360)*pi/180;
r = linspace(0,r);
[Phi360,R] = meshgrid(phi360,r);
Data = griddata(CoordsX, CoordsY, Field, R.*cos(Phi360), R.*sin(Phi360));
subplot(2,2,3)
surf(R.*cos(Phi360), R.*sin(Phi360), Data) % This make the surface-plot with cylindrical coords
You could(should) also take a look at the scatteredInterpolant function since that might be a useful and more flexible multi-call replacement of the griddata-function.
HTH
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!