"For improved robustness, consider replacing i and j by 1i" - Is this an error?
15 views (last 30 days)
Show older comments
I would like to know if the red line is an error. It says that: "For improved robustness, consider replacing i and j by 1i". I need to replace or I can just leave it as it is? Thanks

0 Comments
Accepted Answer
OCDER
on 26 Oct 2017
Matlab uses i and j for imaginary i, or sqrt(-1). This lead to a lot of issues because i and j are often used as counter variables for the for and while loops. Example:
for i = 1:10
plot(ano3, medial5(i-7), 'k'); %Did you mean imaginary i or counter variable i?
end
In your case, it depends on if i is the imaginary i or a variable i. If imaginary i, take their advice and use 1i, or you may end up spending hours looking for the i bug. If variable i, you must declare i before hand, or it'll assume i = 1i.
0 Comments
More Answers (1)
Walter Roberson
on 26 Oct 2017
No, it is a warning. You can leave the code as-is.
... provided, that is, that media15 is a function that expects to be able to take a single complex argument. If that is not the case, you should read the warning as a hint that perhaps you forgot to initialize a variable named i .
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!