How to extract values from specific coordinates

4 ビュー (過去 30 日間)
MRobert
MRobert 2021 年 12 月 30 日
コメント済み: MRobert 2022 年 1 月 1 日
Dear forum,
I have a plane defined by (X,Y) coordinate points on which I interpolated a scalar, as you can see in the figure attached. How may I export the scalar only for some given (X,Y) pairs? For example X = [ -0.05 0 0.05]' , Y = [ 0.01 0.025 0.05]' and I want to get the scalar in (-0.05,0.01), (0,0.025) and (0.05,0.05).
Regards,
Robert

採用された回答

Matt J
Matt J 2021 年 12 月 30 日
編集済み: Matt J 2021 年 12 月 30 日
You can use interp2() or griddedInterpolant().
  5 件のコメント
Matt J
Matt J 2021 年 12 月 31 日
編集済み: Matt J 2021 年 12 月 31 日
It occurs to me that you might not know what "scalar" actually means, and this is creating confusion in the discussion. A scalar is a single number, i.e., a 1x1 matrix. Your code above makes no sense if "Initial_Scalar" is a 1x1 matrix. It also makes no sense that you would expect the output of either F(Xr,Yr) or F(X,Y) to be 1x1 matrices.
It also doesn't make sense that you used griddata if your original data was already gridded.
Here is my first impression of what I think you really want. The point is that it does give a result the same size as X and Y, and griddata is not needed.
X_FirstGrid=linspace(-0.1,0.1);
Y_FirstGrid=linspace(0,0.05);
V=X_FirstGrid.^2.*Y_FirstGrid(:); %Some made-up surface
F=griddedInterpolant({X_FirstGrid, Y_FirstGrid}, V);
X = [ -0.05 0 0.05]' ; Y = [ 0.01 0.025 0.05]';
result = F(X,Y)
result = 3×1
1.0e+-3 * 0.0450 0.0000 0.3750
MRobert
MRobert 2022 年 1 月 1 日
Hello,
Sorry for the way of expressing. Indeed this is what I was looking for!
Thank you,
Regards,
Robert

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by