Why does M-Lint show me a message "END or Colon is apparently used to index an non-array" in MATLAB 7.5 (R2007b)?

1 view (last 30 days)
In the attached example M-Lint displays a message in line 38 for the colon:
ann = an(r,:);
As "an" is not defined before, but will be written out of the Simulink model to the current workspace "an" will be known and the program will run as expected.
If I comment out the function line and execute the code as a script this message does not occur.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
M-Lint shows the message because in its static analysis, it is unable to determine that "an" is a variable. It assumes it is a function and therefore shows that warning. It does not show an error for the statement,
ann = an(r,1:k);
because this is a valid method of accessing a function (passing the vector 1:k as input), and therefore fits in M-Lints assumption about "an". However,
ann = an(r,:);
is not a valid function call and results in an M-Lint error.
This behavior is a little confusing and has been improved in MATLAB version 7.7 (R2008b) and above.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2007b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!