Effacer les filtres
Effacer les filtres

Finding/ returning intermediate value in vector

2 vues (au cours des 30 derniers jours)
Martin Olafsen
Martin Olafsen le 3 Oct 2017
Réponse apportée : KSSV le 3 Oct 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

Réponse acceptée

KSSV
KSSV le 3 Oct 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)

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by