Your time vector is one longer than Gz is.
Your code assumes that M is the same length as time, but M could be larger since M is initialized as 3 by N and we do not know the relationship between N and F.
Note that if N is smaller than F, then M grows inside the loop and so will not be the same size as the fixed-length "time"