How read values from lookup table

Hello,
I have a basic question regarding the reading of value from a table.
for example:
I have an equation , E_OC = E_P - E_N------- (i)
and i have also values of E_OC against Xc in a table, dont know any direct relation between them.
My requirements is when eqution 1 excutes ,it gives me a value of E_OC , and program should work like this ,it will give me Xc value by looking at nearmost E_OC already saved in a table.
The calcuted E_OC may be differ slighty from already saved values of E_OC against Xc.
please help me ,how I should compute this.

5 件のコメント

Walter Roberson
Walter Roberson 2022 年 9 月 10 日
interp1 with 'nearest' interpolation.
KIRAN noor
KIRAN noor 2022 年 9 月 10 日
it gives "NAN" for some values , I want a nearest value if exactly not lie in the table ,but not empty.
Walter Roberson
Walter Roberson 2022 年 9 月 10 日
interp1(1:3, [1, 4, 9], 0:5, 'nearest', 'extrap')
ans = 1×6
1 1 4 9 9 9
KIRAN noor
KIRAN noor 2022 年 9 月 10 日
Thank you Roberson,
But logically thats not correct, as whatever the range I will giveother than 1:3, it will be answe me 9.
as
>> interp1(1:3, [1, 4, 9], 0:10, 'nearest', 'extrap')
ans =
1 1 4 9 9 9 9 9 9 9 9
Walter Roberson
Walter Roberson 2022 年 9 月 10 日
You asked
"program should work like this ,it will give me Xc value by looking at nearmost E_OC already saved in a table"
and that is what it is doing. Notice the 0 input is not extrapolating to 9, it is extrapolating to the nearest to the first parameter, 1:3 and getting 1 and looking up [1, 4, 9](1 ) to get the result.
If you want to search for the nearest to the [1 4 9] then make that the first parameter. Sometimes you want to use something like
interp1([1 4 9], [1 4 9], 0:10, 'nearest', 'extrap')
ans = 1×11
1 1 1 4 4 4 4 9 9 9 9

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2018a

質問済み:

2022 年 9 月 10 日

コメント済み:

2022 年 9 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by