function res = counter
global countdata; %! Declare a variable to hold the state of the counter
if isempty(countdata)
    countdata = 0; %! Initialize the variable when first created.
end
countdata = countdata+1; %! Update it
res = countdata;
