5

I have some prototype MATLAB code that is not required to be very fast.

An array used in the code grows in size, and MATLAB Code Analyzer displays the warning "consider preallocating for speed" in the MATLAB editor. However, I can't know the final size of the array because a decision is taken during its growing process, and I therefore don't wish to preallocate it.

How can I disable the "consider preallocating for speed" warning displayed by MATLAB Code Analyzer in the MATLAB editor?

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • 1
    Take a look [in the documentation](http://www.mathworks.com/help/matlab/matlab_prog/suppress-warnings.html) – Schorsch Jul 02 '13 at 12:59
  • 2
    @Schorsch: doesnt apply, this is not an actual warning that is thrown, its more of an information tip from MATLAB code analyzer: http://www.mathworks.com/help/matlab/matlab_prog/check-code-for-errors-and-warnings.html#brqxeeu-167 – Amro Jul 02 '13 at 13:10

3 Answers3

12

With the Editor open, you could right-click the orange squiggly line and select suppress "<warning msg>" on this line. This will insert a comment %#ok<SAGROW> telling MATLAB Code Analyzer to suppress this warning:

p = [];
for i=1:1000
    p(i) = i; %#ok<SAGROW>
end
Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
Amro
  • 123,847
  • 25
  • 243
  • 454
  • PS: I realize we've been abusing the `%# ...` notation as comments here on Stack Overflow (you might have seen me use in a lot of my posts). This was mainly because the syntax highlighter doesn't properly detect normal comments `% ...`. That's the reason way I created a [userscript](http://meta.stackexchange.com/a/137865/135945) to fix this. The main part has already been accepted upstream ([google-code-prettify](http://code.google.com/p/google-code-prettify/source/detail?r=291)), lets just hope SO upgrade their version. – Amro Jul 02 '13 at 15:06
1

It is not exactly answering your question, i.e. deleting the warning message, but using the answer from Amro here:

Matrix of unknown length in MATLAB?

Would not show you the warning and would give you the possibility to preallocate without clearly knowing the size of your arrays.

Community
  • 1
  • 1
Philippe K
  • 81
  • 1
  • 13
1

If you have a recent version of Matlab, you can right click the underlined code generating warning in the editor and there's an option to suppress the warning.

Hugh Nolan
  • 2,508
  • 13
  • 15