Error on spline function

조회 수: 9 (최근 30일)
Mathew Brown
Mathew Brown 2023년 3월 5일
댓글: Mathew Brown 2023년 3월 10일
Hi All,
I am new to matlab and am trying to downsample variables with different numbers of samples to a preset number (in this instance 51 points). However, when I use the spline function it keeps coming up with the error below:
>> x = linspace(0, 100, width(Cheesie1));
y = 0:50;
reduced = spline(x, Cheesie1, y);
Error using chckxy
The first and second inputs must be of type double or single.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
If anyone can give me an idea as to how to solve this or a better way down downsampling, I would really appreciate it.
Keep well
Mat
  댓글 수: 3
John D'Errico
John D'Errico 2023년 3월 5일
My code often smells a bit like limburger, and sometimes it has holes in it like swiss. And on average, it is never as gouda as I want it to be.
Stephen23
Stephen23 2023년 3월 6일
"it is never as gouda as I want it to be": I also imagine that it will be a Brie-ze to write some tidy code and can hardly curdle my enthusiasm, yet it always matures into something that is barely Feta than nothing, full of holes, and with quite a strong smell to it.

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

채택된 답변

John D'Errico
John D'Errico 2023년 3월 5일
편집: John D'Errico 2023년 3월 5일
Splines cannot be buit from integer data. They also cannot be symbolic. So possibly you are trying to interpolate a logical vector, or a character vector, or possibly, you are trying to interpolate a vector of character representations of numbers? The vector '123456' is NOT a number. Spline cannot operate on that, and return anything meaningful.
Both arguments to spline MUST be either single or double precision numbers. For example, consider the result of this operation:
x = 1:5; % DOUBLE PRECISION
y = '12345'
y = '12345'
spline(x,y)
Error using chckxy
The first and second inputs must be of type double or single.

Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Do you see this is the same error spline gave you?
So you must convert the variable Cheesie into doubles. Use the function double to do that, if the numbers are uint8 or logical. If the numbers in your vector Cheesie are characters, then you need to turn them into actual numeric representations of digits.
Anyway, then remember that the predictions from the spline will not be integers.
  댓글 수: 1
Mathew Brown
Mathew Brown 2023년 3월 10일
Thanks for your help, this was really helpful!

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

추가 답변 (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