Hello, I am not understanding why this little program for interpolation of sin(x) changing the number of points, is not working. Could you help me, please?
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi);
plot(x,y,'o',xi,yi)
Thanks Bye massi

댓글 수: 1

Geoff Hayes
Geoff Hayes 2015년 4월 7일
Massi - please clarify what you mean by is not working. Are you suggesting that if you change the number of points then there is no change to the plot? Re you expecting a better solution if you increase the number of points?

댓글을 달려면 로그인하십시오.

답변 (3개)

Adam
Adam 2015년 4월 7일

1 개 추천

Default interpolation is linear. If you add in 3 points between every pair of points and then linearly interpolate you will just get extra points on the same lines that you had before.
'spline' or 'pchip' will provide some difference.
interpolating a function like that seems a waste of time though as sin(x) itself will do the interpolation job if rerun as:
yi = sin(xi);

댓글 수: 1

massi
massi 2015년 4월 7일
yes thank you, I did it only to try if I am using this function correctly, but I obtain every time the following error:
Error in interpol (line 4) yi = interp1(x,y,xi);

댓글을 달려면 로그인하십시오.

John D'Errico
John D'Errico 2015년 4월 7일
편집: John D'Errico 2015년 4월 7일

0 개 추천

DON'T name a script (or function) interp1. Don't replace existing tools in MATLAB, as then you will later have problems, just like this.
You clearly did so, in a way that apparently calls interpol, a tool that you found on the file exchange. See that this is the error message fragment that is reported by you. It clearly mentions interpol, as called by interp1. In fact, interp1 NEVER calls a function that they don't supply.
"Error in interpol (line 4) yi = interp1(x,y,xi);"
So now you are asking how interp1 works, but really, it is using interpol, a perhaps lesser quality tool that you got from the FEX.
Try these things, and see what it gives you.
which interp1 -all
which interpol -all
type interp1
Mritu Sivaraman
Mritu Sivaraman 2018년 6월 21일

0 개 추천

Can anyone explain me how this interp function works? Thanks

댓글 수: 2

Walter Roberson
Walter Roberson 2018년 6월 21일
interp1() offers a number of different interpolation methods. Which one are you interested in?
Also, is the question about interp1() or about interp2()?
There are MANY methods inside interp1:
'linear' - (default) linear interpolation
'nearest' - nearest neighbor interpolation
'next' - next neighbor interpolation
'previous' - previous neighbor interpolation
'spline' - piecewise cubic spline interpolation (SPLINE)
'pchip' - shape-preserving piecewise cubic interpolation
'cubic' - same as 'pchip'
'v5cubic' - the cubic interpolation from MATLAB 5, which does not
extrapolate and uses 'spline' if X is not equally
spaced.
'makima' - modified Akima cubic interpolation
To answer this question could take many hours to write. Some of those methods are alone worth many hours to write a complete explanation. So, if you want to understand interp1, then read the documentation for interp1. At the end, you will find references.
Or, ask a SPECIFIC question, about a SPECIFIC method in interp1.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2015년 4월 7일

댓글:

2018년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by