MATLAB Answers

0

Spline interpolation is giving me errors with array index

Asked by Nassim Zahrir on 2 Apr 2019
Latest activity Answered by Akira Agata
on 3 Apr 2019
Here is my code:
t = linspace(0,2*pi,8)';
f = sin(t).^2 ;
xx = linspace(0,2*pi);
yy = spline(t,f,xx);
and
Here is the error it is giving me:
Index in position 1 is invalid. Array
indices must be positive integers or
logical values.
Error in (line 4)
yy = spline(t,f,xx);

  0 Comments

Sign in to comment.

1 Answer

Answer by Akira Agata
on 3 Apr 2019

At least the latest version R2019a, your code works well.
Anyway, I would recommend adjusting vector direction of t and xx, like:
t = linspace(0,2*pi,8)'; % Column vector
f = sin(t).^2 ;
xx = linspace(0,2*pi)'; % Column vector
yy = spline(t,f,xx);

  0 Comments

Sign in to comment.