How to get Y-values from X-values?

8 ビュー (過去 30 日間)
Sohel Rana
Sohel Rana 2020 年 9 月 28 日
編集済み: Sindar 2020 年 9 月 28 日
Hi,
I have lot of data in excel file where column 1 denotes the X-value and column to denotes the Y-value. I tried to get Y-value to corresponind X-value using interp1 (X,Y, certainX) but the following error shows:
Error using griddedInterpolant
The grid vectors must contain unique points.
I can get values by first interpolating yq=(X,Y, xq) but it changes the graph position and does not give the exact value. Suppose I want Y value for a X=1600. When I see at the X-values from workspace, I can see there is a X value of 1601.35 but not 1600. As a result, it shows Y-value NAN.
Is there any way to use tolerance that will cover 1600+/- 2 and will give the corresponding Y value.
I would really appreciate your help.

採用された回答

Sindar
Sindar 2020 年 9 月 28 日
編集済み: Sindar 2020 年 9 月 28 日
if you just want the Y value for the nearest point:
[~,idx] = min(abs(X-certainX));
certainY = Y(idx);
I don't see quite that error. Is certainX just a number?
  1 件のコメント
Sohel Rana
Sohel Rana 2020 年 9 月 28 日
Perfect! This is exactly what I wanted. Thank you so much.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by