Hello guys , please help me ! I

3 次查看(过去 30 天)
Dombrovschi Andrei
I have two vectors :
x= [1 2 3 4 5 6]
and
y=[2.3 4.3 5 4.7 9 12]
and i need to find the value of y in x = 3.5
  6 个评论
Dombrovschi Andrei
编辑:per isakson 2018-2-1
x= [1 2 3 4 5 6]
y=[2.3 4.3 5 4.7 9 12]
figure
plot(x,y,'r-')
value = xx==3.5(find(y));
hold on
plot(3.5,value,'r*')
per isakson
per isakson 2018-2-1
Isn't that interpolation
>> interp1( x, y, 3.5 )
ans =
4.8500

请先登录,再进行评论。

回答(2 个)

Star Strider
Star Strider 2018-2-1
It is an interpolation, regardless of the method you want to use. There are likely several ways to do this.
Using interp1:
x = [1 2 3 4 5 6];
y = [2.3 4.3 5 4.7 9 12];
idx = find(x <= 3.5, 1, 'last');
yi = interp1(x(idx:idx+1), y(idx:idx+1), 3.5, 'linear')
yi =
4.8500
If you want to use the 'previous', 'next', or 'nearest' methods instead of 'linear', the results are 5, 4.7, and 4.7 respectively.

Dombrovschi Andrei
thanks guys !

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by