Hi! If I understand correctly, I was able to make this work by setting figure handles before the for loop, toggling between the figures inside the for loop, and using hold on to plot data on the same figure in each loop.
% SET THE FIGURE HANDLES.
f1 = figure;
f2 = figure;
% SET UP SOME STUFF OUTSIDE THE FOR LOOP.
% Put in your x values here. I just made a list of logarithmic values.
psd_x = [1, 10, 100, 1000];
% Put in your y values here. I just made a matrix of random numbers less than 100.
PSD_avg = rand(100,10,4);
% Put in your y error here. I just made a matrix of random numbers less than 10.
PSD_std = rand(10,10,4);
% START THE FOR LOOP.
for k = 1:10 % Put in how many iterations you want here. I just used 10.
py_yr =PSD_avg(k,1:4); % I'm using the first four columns. You should change this to fit yours.
py_stdyr=PSD_std(k,1:4);
% Plot stuff on the first graph.
set(0, 'CurrentFigure', f1) % Select the first graph
hold on % To keep all of the current data on the graph.
plotpsd=semilogx(psd_x,py_yr,'-o'); % Plot the stuff.
% Plot stuff on the second graph.
set(0, 'CurrentFigure', f2)
hold on
plotstd=semilogx(psd_x,py_stdyr,'-o');
end
% MAKE THE GRAPHS LOOK NICE.
% Make the first graph look good.
set(0, 'CurrentFigure', f1)
title('PSD at year');
set(gca,'Fontsize',12);
ylabel('dV/dlnr');
hold off % Finish the first graph.
%Make the second graph look good.
set(0, 'CurrentFigure', f2)
title('Standard deviation at year');
set(gca,'Fontsize',12);
ylabel('dV/dlnr');
hold off % Finish the second graph.
I wasn't totally sure what you were trying to do with the titles, but I'm sure you can figure that part out!
Hope this helps! Good luck!