Here is how to do a for loop:
main_folder = pwd;%uigetdir;
subfolder = 'foldername';
% Making up values so I can show preview plot
TD_32 = rand(2000,32,120)-0.5;
Time_vec = 1:8000/2000:8000;
%% mean LFP [use TD_32 to plot]
mean_LFP_fil = mean(TD_32, 3);
for trial = 1:size(TD_32,3)
%% features extraction and single channel selection [plot 2, 3]
for channel = 10:20
[M,I] = min(mean(TD_32(:,channel,:),3));% principal peak amplitude and latency
%% plot 2 A [single channel mean LFP]
pr_peak_amp = M*10e13;
pr_peak_lat = I;
fig_name_3 = ['Channel ' num2str(channel) ' mean LFP' ' Trial ' num2str(trial)];
figure(3)
plot(Time_vec, mean(TD_32(:,channel,:),3))
title(fig_name_3)
hold on
plot(get(gca,'xlim'), [0 0], 'k--')
plot([0 0], get(gca,"YLim"), 'k--')
plot([0 0]+.5,get(gca,'ylim'),'k--')
xlabel('Time (s)'), ylabel('activity (\muV)x100')
xline(5000,'--r')
text(I, 0, sprintf('Principal peak latency: %f ', pr_peak_lat))
plot(I, M,'-','MarkerSize',8,'Color','b')
text(I, M, sprintf('Principal peak amplitude: %f ', pr_peak_amp))
plot(I, M,'o','MarkerSize',6,'Color',[1 0 0])
set(gca,"XLim")
saveas(gcf,[main_folder,filesep,subfolder,filesep,fig_name_3],'png')
end
end