登录论坛

查看完整版本 : Can we configure MATLAB let variable have minium local scope?


poster
2019-11-27, 15:00
<p>Can we configure MATLAB let variable have minium local scope?</p>

<p>I want matlab something similiar like C below.</p>

<pre><code>% after some configure ...

for i=1:1:100
a=i*i
end
% here we can not using 'a' any more for it have local scope in for loop.
</code></pre>

<p>Why I want it becase the scope in whole script sometimes leds to bug hard to find.</p>

<p>For example:</p>

<pre><code>% get accumulate of b via 100 times of x_0
b=0;
for i=1:1:100
x0=100
b=b+x0
end

% get accumulate of a via 100 times of x_0
a=0
for i=1:1:100
x_0=100
a=a+x0 %mistype x_0 to x0, and hard to find
end
</code></pre>

<p>Thanks advance.</p>



More answer... (https://stackoverflow.com/questions/59064467/can-we-configure-matlab-let-variable-have-minium-local-scope)