Don’t number the figures. They will increment themselves.
Try this:
t=linspace(1,20,10000); %10000 Datapoints
f1=8;
f2=9;
A=1;
w= A*sin(f1*t); %Blue Wave
for f2=[9 9.5 13 15]
w2=A*sin(f2*t); %Red Wave
% First Graph:
figure
plot(t(1:1000),w(1:1000)) %Only Graphing 2T
hold on
plot(t(1:1000),w2(1:1000))
hold off
title(['Frequencies used= ',num2str(f1),' and ',num2str(f2)])
ylabel(['Amplitude= ',num2str(A)])
% Second Graph:
figure
y=w+w2;
plot(t,y)
title(['Added Waves. Frequencies used= ',num2str(f1),' and ',num2str(f2)])
ylabel(['Amplitude= ',num2str(A)])
%Third Graph:
figure
subplot(2,1,1)
plot(t,y)
title(['Composite. Frequencies used= ',num2str(f1),' and ',num2str(f2)])
ylabel(['Amplitude= ',num2str(A)])
subplot(2,1,2)
plot(t(1:1000),w(1:1000)) %Only Graphing 2T
hold on
plot(t(1:1000),w2(1:1000))
hold off
title(['Frequencies used= ',num2str(f1),' and ',num2str(f2)])
ylabel(['Amplitude= ',num2str(A)])
end
The only other change I made was to move ‘w’ outside the loop. There is no need to recalculate it each time if it doesn’t change.