Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does %#ok<SAGROW> comment mean in MATLAB?

I've encountered many MATLAB codes which have a %#ok<SAGROW> comments. This comment is used in different circumstances and I can't figure it out what it means.

As an example:

i = 1; 
flag = true;
for l = 1:k
    while(flag==true)
        if(probs(i)~=0)
            leaves(l).val = i-1; %#ok<*SAGROW>
            leaves(l).zero = '';
            leaves(l).one = '';
            leaves(l).prob = probs(i);
            i = i + 1; 
            flag = false;
        else
            i = i+1;
            flag = true;
        end
    end
flag =true;
end

There are other references to this comment too, for instace:

  • http://www.codeproject.com/Questions/151765/answer.aspx
  • http://www.scribd.com/doc/69869075/EEE-554-Matlab-Solutions
  • http://www.mathworks.com/matlabcentral/newsreader/view_thread/321047
  • http://www.nd.edu/~jrunkle1/ballis_problem.m
like image 299
Isaac Avatar asked Jun 19 '12 09:06

Isaac


Video Answer


3 Answers

It suppresses mlint warnings. In this specific case, it is about not pre-allocating an array.

mlint is one of the static code analysis tools that Matlab has. It finds possible errors and shows warnings.

Edit(1): I've just noticed that your question is about SAGROW, not AGROW. I could not find it. My guess is that it is an old/new mlint syntax.

like image 196
Andrey Rubshtein Avatar answered Oct 19 '22 13:10

Andrey Rubshtein


I don't know about SAGROW, but AGROW would mean that a given array/vector/matrix <name> might be growing inside a loop. Consider preallocating for speed.

like image 37
glglgl Avatar answered Oct 19 '22 13:10

glglgl


General answer (for different values in the angle brackets):

Type msgid:SAGROW in Preferences -> Code Analyzer.

For others msgid:<your-ok-msg-id>.

edit: shortest way, 1. remove the comment, 2. read the codeanalyzer tooltip of the underline piece of code.

like image 33
PythoNic Avatar answered Oct 19 '22 14:10

PythoNic