MATLAB: Am i receiving “Array indices must be positive integers or logical values.” error

indexinglinspaceMATLAB

I keep getting some sort of indexing error when running my code, but cannot find the error. Please help.
x0 = 0;
v0 = 2;
wn = 8;
ez = 0.07;
wd = wn * sqrt(1-ez^(2));
t = linspace (0, 10, 937);
x(t) = exp(-ez.*wn.*t) .* (x0.*cos(wd.*t) + ((v0+(ez.*wn.*x0))./wd)…
.* sin(wd.*t))

Best Answer

The problem:
t = linspace (0, 10, 937);
x(t) = exp(-ez.*wn.*t) .* (x0.*cos(wd.*t) + ((v0+(ez.*wn.*x0))./wd)...
.* sin(wd.*t))
First, ‘t’ begins with a 0, and the other values are almost all decimal fractions, not integers. Positive integers are integers greater than 0.
The solution is to delete the subscript.
This works:
x = exp(-ez.*wn.*t) .* (x0.*cos(wd.*t) + ((v0+(ez.*wn.*x0))./wd)...
.* sin(wd.*t));