MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

  • Displays a variable with shared scope in teal blue, regardless of the cursor location.
    For instance:


Example of Using Automatic Function and Variable


Highlighting


Consider the code for a function rowsum:


function rowTotals = rowsum
% Add the values in each row and
% store them in a new array


x = ones(2,10);
[n, m] = size(x);
rowTotals = zeros(1,n);
for i = 1:n
rowTotals(i) = addToSum;
end


function colsum = addToSum
colsum = 0;
thisrow = x(i,:);
for i = 1:m
colsum = colsum + thisrow(i);
end
end


end


When you run this code, instead of returning the sum of the values in each row and
displaying:


ans =


10 10


MATLAB displays:


ans =


0 0 0 0 0 0 0 0 0 10


Check Variable Scope in Editor
Free download pdf