Suzan Cioc
Suzan Cioc

Reputation: 30097

How can I disable Code Analyzer warnings in the MATLAB editor?

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?

Upvotes: 5

Views: 3383

Answers (3)

Amro
Amro

Reputation: 124563

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

Upvotes: 13

Hugh Nolan
Hugh Nolan

Reputation: 2519

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.

Upvotes: 1

Philippe K
Philippe K

Reputation: 81

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.

Upvotes: 1

Related Questions