I am using a function and i want to update counter on each function call and use value of that counter for some condition.But every function call counter initialize to zero and if i use counter=counter+1 it always give counter =1 so how to do this?
Show older comments
The variable counter value should be equal to number of times function call.
Accepted Answer
More Answers (1)
MathReallyWorks
on 26 May 2017
Hello Amit,
Keep your initialization on top of the code (i.e. outside of loop if any).
Check if it is in any loop which is causing it to initialize again.
counter=0
should be above the code (i.e. outside of loop)
and
counter=counter+1
should be inside the loop.
If you want a better answer, attach your code.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!