Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Matlab, error using length(x), gives subscript indicies error

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?

like image 852
user1757741 Avatar asked Nov 26 '25 15:11

user1757741


1 Answers

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.

like image 181
Praetorian Avatar answered Nov 29 '25 19:11

Praetorian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!