Error on spline function

10 visualizaciones (últimos 30 días)
Mathew Brown
Mathew Brown el 5 de Mzo. de 2023
Comentada: Mathew Brown el 10 de Mzo. de 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 comentarios
John D'Errico
John D'Errico el 5 de Mzo. de 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 el 6 de Mzo. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 5 de Mzo. de 2023
Editada: John D'Errico el 5 de Mzo. de 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 comentario
Mathew Brown
Mathew Brown el 10 de Mzo. de 2023
Thanks for your help, this was really helpful!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by