It is good practice to avoid
j variables to prevent confusion about them being variables or the imaginary unit.
Personally, however, I use
j as variables quite often as the index of short loops. To avoid problems in my own code, I follow another good practice regarding
j: don’t use them to denote imaginary numbers. In fact, MATLAB’s own documentation states:
For speed and improved robustness, you can replace complex
So rather than avoiding two very commonly used variable names because of a potential conflict, I’m explicit about imaginary numbers. It also makes my code more clear. Anytime I see
1i, I know that it represents
sqrt(-1) because it could not possibly be a variable.