how to use interp1() function

71 次查看(过去 30 天)
I have tried to use interpt(1) function as i have time and pressure data.
the pressure data is highly scattered it look like that
firstly,I have used function : p0q=interp1(p0,tq) as show belows
_____________________________________________________________________________________
t1=t(x1:x2);
p01=p0(x1:x2);
tq=t(x1):0.000001:t(x2);
p0q=interp1(p0,tq);
figure
plot (t1,p01,'o',tq,p0q,'*');
legend('p01','p0q');
_____________________________________________________________________________________
but the poq (interpolated result is empty) as shown in the figure
when i change it to
p0q=interp1(p0,tq,'pchip');
the interploted data are incorrect
is there something wrong in my code?or i am using the function incorrectly?

采纳的回答

Stephen23
Stephen23 2020-2-12
编辑:Stephen23 2020-2-12
The problem is that you are using the default x values, which for a vector input are defined as
1:numel(v)
These default points only make sense if you are also requesting interpolation for x>=1 and x<=numel(v), but look at the x points you are requesting interpolation at: judging by your screenshot they are somewhere between 0.06162 and 0.06067. The points you are requesting lie nowhere close to the the input x values (for which you used the default values 1:numel(v), and which iare thus totally unsuitable for your task).
The solution is simple: you need to provide the input x values, i.e.:
p0q = interp1(t1, p0, tq);
  1 个评论
zein
zein 2020-2-12
编辑:zein 2020-2-12
yes,I wrote the line incorrectly, it should be writtien like that
p0q=interp1(t1,p01,tq,'linear');
3.JPG

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by