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

10 Ansichten (letzte 30 Tage)
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 Kommentare
alpedhuez
alpedhuez am 20 Dez. 2020
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 am 2 Aug. 2021
Bearbeitet: Robert Laws am 2 Aug. 2021
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 19 Dez. 2020
That is the simpler way.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by