A common mistake MATLAB coders have, is using the length function for matrices (as opposed to vectors, for which it is intended). The length function, as mentioned in its documentation, "returns the length of the largest array dimension" of the input.
For vectors, the return value of leng...