How to keep track of last change in a variable inside the loop?
Ältere Kommentare anzeigen
Suppose I have a variable NN, and I am applying for loop 40 times....each loop may or may not change the variable NN....I want to know what is the last loop where the variable NN changes....for example:if the last change of NN occurs at 35th loop and no changes thereafter then, how should I know that it last changes at 35th loop by using the code?... can anyone help
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 25 Jul. 2015
Bearbeitet: Azzi Abdelmalek
am 25 Jul. 2015
You can use a counter. Example
for k=1:40
a=sin(k)
if a>0.5
y=a
ii=k
end
end
disp(ii)
1 Kommentar
peyush
am 26 Jul. 2015
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!