MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
Suppress an Instance of a Message in the Current File

You can suppress a specific instance of a Code Analyzer message in the current file. For
example, using the code presented in “Check Code for Errors and Warnings” on page 24-
6 , follow these steps:

(^1) In line 49, right-click at the first underline (for a single-button mouse, press Ctrl
+click).
2 From the context menu, select Suppress 'Terminate statement with semicolon...'



On This Line.
The comment %#ok appears at the end of the line, which instructs MATLAB
not to check for a terminating semicolon at that line. The underline and mark in the
indicator bar for that message disappear.
(^3) If there are two messages on a line that you do not want to display, right-click
separately at each underline and select the appropriate entry from the context menu.
The %#ok syntax expands. For the example, in the code presented in “Check Code for
Errors and Warnings” on page 24-6, ignoring both messages for line 49 adds
%#ok<NBRAK,NOPRT>.
Even if Code Analyzer preferences are set to enable this message, the specific
instance of the message suppressed in this way does not appear because the %#ok
takes precedence over the preference setting. If you later decide you want to check
for a terminating semicolon at that line, delete %#ok from the line.
Suppress All Instances of a Message in the Current File
You can suppress all instances of a specific Code Analyzer message in the current file. For
example, using the code presented in “Check Code for Errors and Warnings” on page 24-
6, follow these steps:
(^1) In line 49, right-click at the first underline (for a single-button mouse, press Ctrl
+click).
(^2) From the context menu, select Suppress 'Terminate statement with semicolon...'
In This File.
The comment %#ok<*NOPRT> appears at the end of the line, which instructs MATLAB not
to check for a terminating semicolon throughout the file. All underlines and marks in the
message indicator bar that correspond to this message disappear.
24 Coding and Productivity Tips


Free download pdf