Fixed the NaN caused by an integer-division by nStates in the Matlab version of the code (thanks to Javier Juan Albarracin).

Fixed the NaN caused by an integer-division by nStates in the Matlab
version of the code (thanks to Javier Juan Albarracin).