Your new figures are not taking over as the current figure (gcf).
To explicitly specify where a plot will go, you can call it with the syntax plot(HA,...). From the MATLAB docs:
plot(axes_handle,___) plots into the axes specified by axes_handle instead of into the current axes (gca)
To use this, you would make a figure and axes, storing their handles, like so:
hf = figure; ha = axes('parent',hf); plot(ha,x,y)
P.S. I just saw that you got it to work by putting a close all before your loop! I'll keep the answer here for reference since it is a good way to be explicit with your plotting.
figure(x)inside the for-loop? but always with the same numberx? Use a different number every iteration and it will create a new figure, or usehold onbehind the plot command, to plot multiple graphs in the same figure.close all; figure; figure;, does it create 2 figures?figure(1); figure(2);? Two figures?