MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
Examine the code by following these steps:

1
On the Home tab in the Environment section, click Preferences and select
MATLAB > Colors > Programming tools. Ensure that Automatically highlight
and Variables with shared scope are selected.

(^2) Copy the rowsum code into the Editor.
Notice the variable appears in teal blue, which indicates i is not a local variable.
Both the rowTotals function and the addToSum functions set and use the variable i.
The variable n, at line 6 appears in black, indicating that it does not span multiple
functions.
(^3) Hover the mouse pointer over an instance of variable i.
A tooltip appears: The scope of variable 'i' spans multiple functions.
(^4) Click the tooltip link for information about variables whose scope span multiple
functions.
(^5) Click an instance of i.
Every reference to i highlights in sky blue and markers appear in the indicator bar
on the right side of the Editor.
20 Function Basics

Free download pdf