필터 지우기
필터 지우기

Finding/ returning intermediate value in vector

조회 수: 2 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by