MATLAB Community

MATLAB, community & more

Automatic Variable Highlighting

Another new feature in the MATLAB R2010b Editor is the automatic highlighting of variable and subfunction names. Highlighting a variable or subfunction usage is easy, just click on any variable or subfunction name in the editor, and after a brief pause, all the usages of that variable or subfunction will be highlighted in light blue.

Highlighted variable in MATLAB Editor

In addition to showing the usages of the selected variable in the text, all of the highlights are overlaid on the right-side information bar. If there are M-Lint messages present, those will be dimmed to make it easier to see the variables or subfunctions. Finally, a count is presented in the editor’s status bar (or MATLAB’s status bar if the editor is docked in MATLAB’s main window). If there is only one usage of that name, it will not be highlighted, but the informational message will still be displayed.

If there are multiple usages, hovering over the blue-gray stripes in the message panel will display the line of code where that variable or subfunction appears, with the name highlighted. This way you can see code that may be off-screen.

Tooltip showing variable usage offscreen

We think for most users this functionality is very useful for editing and debugging, and the feedback so far has been very positive. But we know that some of you may want to change the color or disable the auto-highlighting feature. This can be done in the new Colors preferences panel. File -> Preferences -> Colors -> Programming Tools -> Variable and function highlighting colors -> Automatically Highlight. If you do disable the automatic highlighting, you will see that you will then be able to highlight variables and subfunction names on-demand with a keyboard shortcut or context menu.

Variable highlighting preferences

The highlighting does have some limitations. It will only find the matching names in code that are in scope. For instance, if you have pass a variable “x” to a subfunction as input argument “x”, the highlighting feature will only highlight the “x”s in either the main function or the subfunction, but not both. And, it won’t recognize that “x” in a comment or string passed to the eval function.

|
  • print

コメント

コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。