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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!