Error on spline function

10 次查看(过去 30 天)
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.

更多回答(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