i and j in MATLAB both have the default value of the complex unit. When you say
you override this, so now i takes the value in that for loop.
When you say
you then reset i to be equal to the complex unit again. This is not an integer or logical so cannot be used as an index. I supsect what you want to do is