Matlab, automatically delete the index variable after the execution of a loop, Part 2
10 次查看(过去 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 个评论
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
2020-12-19
That is the simpler way.
2 个评论
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!