MATLAB: Not recognizing 3.2220e+03 as a positive integer

errorfaqMATLAB

I'm getting the error below:
arraynum =
3.2220e+03
Array indices must be positive integers or logical values.
Error in kaboomSpeed (line 3)
velocityAtImpact= velocity(arraynum);
but I can type velocity(3.2220e+03) into the command line and it works so why wont it work in my function?
function[velocityAtImpact]= kaboomSpeed(velocity,lengthOfFlight,dt)
arraynum=lengthOfFlight/dt
velocityAtImpact= velocity(arraynum);
end
Thanks in advance to anyone who can help me with this.

Best Answer

Since arraynum is a computed value, not something you typed in, it's close to an integer but not exact. This is a FAQ, so read the FAQ and if that doesn't explain it well enough, then write back. Maybe you just want to pass arraynum into round:
arraynum = round(lengthOfFlight/dt);