Finding/ returning intermediate value in vector

3 ビュー (過去 30 日間)
Martin Olafsen
Martin Olafsen 2017 年 10 月 3 日
回答済み: KSSV 2017 年 10 月 3 日
Hi
Say I have a vector:
x = [5 20 15 17]
Is there any way to access values with any intermediate index? For example x(2.5)=17.5 or x(1.37)=10.55? I realise I could interpolate or calculate it by ratios. I'm looking for the easiest way to do this.
I'm also looking for the other way around. Say I have a strictly increasing vector, is there any way to find position of a value? For example
y = [1 5 7 14]
Is there a function such that: function(y, 3) = 1.5. (Is there any way to do this if it isn't strictly increasing/decreasing?)
Regards

採用された回答

KSSV
KSSV 2017 年 10 月 3 日
USe interp1. Read about it.
% Question 1
x = [5 20 15 17] ;
idx = 1:length(x) ;
interp1(idx,x,2.5)
interp1(idx,x,1.37)
% Question 2
y = [1 5 7 14] ;
x = 1:length(y) ;
interp1(y,x,3)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by