How to count the number of times I called a function (using the command line)
Show older comments
Hi,
The backstory: So I'm trying to design an image analysis tool on App Designer where I "feed" an image through a function, do some analysis in my function, output numerical results, verfiy to see if the analysis was done correctly visually, save the function outputs into a spreadsheet, and repeat the process with a different image. The first time the function is called, the results will be stored in the first row of the array; the second time it is called it will be stored in the second row of the array so on and so forth. I figured that to do this, I need to have someway to keep track of how many times my function is called. So I'm testing this with a simpler example:
function p = myfunction(a,b,c)
counter=0; %Initializing counter
parabola
function parabola
e = a+5
f = b+10
g= c+100
store=[e,f,g] %Still figuring out how to define the row associated with the counter to store my variable
end
counter = counter+1
end
However, I'm at to how I can not make the counter reset everytime I pass a new function.
For instance, if I were to do myfunction(1,2,3) followed by myfunction(2,3,4) I would still get counter =1.
Any help for this novice will be highly appreciated!!
Accepted Answer
More Answers (2)
Steven Lord
on 2 Jun 2020
1 vote
Since you're doing this as part of an App Designer app, why not store the iteration count in a property of your app? As long as you have a handle to the app in one of the functions being called, it can either retrieve and update that property directly or pass the property value into a function that's not an app method, receive an updated value from that function when it returns, and store the updated value back into the property.
1 Comment
William Pang
on 2 Jun 2020
Ranitha Mataraarachchi
on 16 Nov 2020
0 votes
Hi. Maybe you found yourself a way out. But you could've defined the 'counter' as a global variable and increment the counter inside the function.
Categories
Find more on Startup and Shutdown 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!
