Error on spline function
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mathew Brown
il 5 Mar 2023
Commentato: Mathew Brown
il 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 Commenti
John D'Errico
il 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
il 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.
Risposta accettata
John D'Errico
il 5 Mar 2023
Modificato: John D'Errico
il 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'
spline(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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!