MATLAB: Matlab code problem in a S-function

s-function

Hi, I have this loop in my code:
global counter
T=200
if counter>=T
counter=0
.
.
else counter=counter+1
end
This code worked fine yesterday and now no, but I have not changed anything. Until yesterday, the answer was
counter =
1
.
.
counter =
200
and now:
counter =
[]
.
.
counter =
[]
Please help me

Best Answer

When you enter the routine counter is null for some reason. Probably some other part of your code did it. Change the line
if counter>=T
to this
if isempty(counter) || counter >= T
That should make it not null anymore.