Matlab, automatically delete the index variable after the execution of a loop, Part 2

11 ビュー (過去 30 日間)
suppose I have a loop
for i=1:10
T(i,:)='NY';
end
then I want to clear the index variable 'i'. One way is to do
clear i
But is there a simpler way?
  6 件のコメント
alpedhuez
alpedhuez 2020 年 12 月 20 日
I agree that it will not matter from the execution perspective. But I need to send a script to a person and that person is not a programmer. So I need to clean up eveything as much as I can.
Robert Laws
Robert Laws 2021 年 8 月 2 日
編集済み: Robert Laws 2021 年 8 月 2 日
It would be very useful if there was an option to have Matlab always clear the loop variable on exit from the loop. That is to say, the loop variable should have a scope only within the loop.
As things stand, the careful programmer has to put "clear loopvariable" after every closing "end" statement, which is tedious.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2020 年 12 月 19 日
That is the simpler way.
  2 件のコメント
madhan ravi
madhan ravi 2020 年 12 月 19 日
If you have multiple loops , use the same index variable for all of them and finally use
clear index_variable
alpedhuez
alpedhuez 2020 年 12 月 19 日
Can have some options I guess

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by