Extract output data from meshgrid input

I have some data which I have interpolated as follows:
Data = load("data.txt")
x = Data(:,1);
y = Data(:,2);
z = Data(:,3);z=-z;
c = Data(:,4);
F = scatteredInterpolant(x,y,z,c);
N = 50;
xvec = linspace(min(x), max(x), N);
yvec = linspace(min(y), max(y), N);
zvec = linspace(min(z), max(z), N);
[xq, yq, zq] = meshgrid(xvec, yvec, zvec);
vq = F(xq, yq, zq);
What I want to do is to extract the value of vq for a given xq,yq,zq.
Like vq(xq==21.7267 & yq==36.9072 & zq==-0.9551), which gives me an empty column vector.
If I do F(21.7267,36.9072,-0.9551) is this the correct vq?

2 件のコメント

darova
darova 2021 年 2 月 14 日
Please attach the data
tandemuse
tandemuse 2021 年 2 月 14 日
I have uploaded the data

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

 採用された回答

Cris LaPierre
Cris LaPierre 2021 年 2 月 14 日
編集済み: Cris LaPierre 2021 年 2 月 14 日

0 投票

Always more helpful for us if you share 1) your data and 2) the complete error message (all the red text).
This example on the scatteredInterpolant documentation page shows how to use the results of meshgrid to determine vq. Make sure you are using the 4th input correctly. MATLAB expects it to be the sample values, specified as a vector that defines the function values at the sample points, v = F(x,y,z).

5 件のコメント

tandemuse
tandemuse 2021 年 2 月 14 日
I have uploaded the data. There is no error message I just get an empty column vector.
Walter Roberson
Walter Roberson 2021 年 2 月 14 日
I don't think that is the issue. The issue is that the logical comparisons were each true for multiple locations, and indexing with multiple selected values in multiple indices gets you results at the cross-product rather than at the intersection.
tandemuse
tandemuse 2021 年 2 月 14 日
編集済み: tandemuse 2021 年 2 月 14 日
If I do F(21.7267,36.9072,0.9551) is this the correct vq?
Walter Roberson
Walter Roberson 2021 年 2 月 14 日
Yes, that would recalculate rather than extract from the stored value.
However is your z positive or negative? You changed sign compared to your other comments
tandemuse
tandemuse 2021 年 2 月 14 日
True it should be negative

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 14 日

0 投票

vq(xq==2 & yq==3 & zq==5)

3 件のコメント

Walter Roberson
Walter Roberson 2021 年 2 月 14 日
better yet is ismembertol instead of ==
tandemuse
tandemuse 2021 年 2 月 14 日
vq(xq==21.7267 & yq==36.9072 & zq==-0.9551) gives me an empty column vector
Walter Roberson
Walter Roberson 2021 年 2 月 14 日
That why I said to use ismembertol()

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

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

リリース

R2020b

質問済み:

2021 年 2 月 14 日

編集済み:

2021 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by