3

Im extracting time-dependent data from a .dat file, and using the spline function, matching the values to an existing time-vector in use. For some reason the length function is failing to read the length of the vector.

I can recreate the error with this blurb:

x = linspace(1,98,76)';
y = 20.*x-5.*x.^2;
t = linspace(0,100,1000)';
yy = spline(x,y,t);
length(yy)

It returns

??? Subscript indices must either be real positive integers or logicals.

It shows in my workspace that yy is 1000x1 double, and max(size(yy)) works fine. Any idea on what creates this error?

  • I do not get an error running that code on R2012b on Linux Mint. Try adding `clear` to the top of your blurb, and if it starts working correctly, then you will know that Praetorian's idea is correct. – Colin T Bowers Oct 18 '12 at 22:47
  • I also do not get an error in R2010b on ubuntu 10.04. – jespestana Oct 21 '12 at 10:45
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 15:51

1 Answers1

8

You probably have a variable named length in your workspace. Use the whos command to see if this is the case.

whos length

This will print out the size and type of the variable length if it exists.

Praetorian
  • 106,671
  • 19
  • 240
  • 328