Finding/ returning intermediate value in vector

5 Ansichten (letzte 30 Tage)
Martin Olafsen
Martin Olafsen am 3 Okt. 2017
Beantwortet: KSSV am 3 Okt. 2017
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

Akzeptierte Antwort

KSSV
KSSV am 3 Okt. 2017
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)

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by