# Finding/ returning intermediate value in vector

11 ビュー (過去 30 日間)
Martin Olafsen 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 2017 年 10 月 3 日
% 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)

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

### カテゴリ

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by