'M1' in the script is a 1000 x 1 array i.e. a column vector with only one column.
'M1(1,o)' tries to extract the array element from row 1 and column 'o' which does not exist since 'o' is varying from 1 to 1000 and there is only one column in 'M1'.
I assume you wanted to extract the 'o'th entry from 'M1' and therefore changing 'M1(1,o)' to 'M1(o,1)' will resolve the error of index exceeding matrix dimensions.
Furthermore, the negative values obtained from the 'max' function are because, when dealing with complex inputs, 'max' operates on the magnitude of the input arguments and returns the one with the largest magnitude - see here. For example, max of complex(-3) [magnitude 3] and complex(2) [magnitude 2] will return complex(-3). In the script, 'Stcev' is a complex double array dealing with complex numbers. Since, mag(0) < mag(<complex numbers in Stcev>), 'max' returns the negative (real part) complex numbers only as output.
N.B: Even if a complex number has its imaginary part to be 0 (for e.g., 3+0i), it is still complex which can be verified by the 'isreal' function.
To learn more about the functionalities of 'isreal', you can refer its documentation page by executing the following command from MATLAB Command Window:
Hope this would solve your queries. Thanks!