필터 지우기
필터 지우기

Interpolating a function that is constant over some parts of its domain?

조회 수: 5 (최근 30일)
I'm trying to write code that will linearly interpolate samples from a generic real-valued function. Interp1 seems to break if the function is constant over any part of its domain, and unfortunately for me this is an extremely common use case - as a simple function:
{0, if x<0
f(x) = {x, if 0<=x<=1
{1, otherwise
It seems like interp1([0, 0, 1, 1], [-10,0,1,10], x) ought to return this function (for x \in [-10,10]), but instead I get the error that "The grid vectors must contain unique points."
Is there another interpolation function that doesn't break when you feed it functions that are sometimes constant?
  댓글 수: 1
Stephen23
Stephen23 2017년 6월 12일
The interp1 help page shows the syntax:
vq = interp1(x,v,xq)
where x is the independent variable. You have the x and v swapped around.

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

채택된 답변

David Goodmanson
David Goodmanson 2017년 6월 12일
편집: David Goodmanson 2017년 6월 12일
Hi Jonathan,
just swap inputs,
interp1([-10,0,1,10], [0,0,1,1], x)

추가 답변 (0개)

카테고리

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