Error on spline function

10 views (last 30 days)
Mathew Brown
Mathew Brown on 5 Mar 2023
Commented: Mathew Brown on 10 Mar 2023
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 Comments
John D'Errico
John D'Errico on 5 Mar 2023
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 on 6 Mar 2023
"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.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 5 Mar 2023
Edited: John D'Errico on 5 Mar 2023
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 Comment
Mathew Brown
Mathew Brown on 10 Mar 2023
Thanks for your help, this was really helpful!

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!