function Plot_rates(rates,PC1,bins)

% Plot the firing rates of the spike trains of each group, along with their
% 1st principal component

groups=size(PC1,2);                                                         % Count the number of groups
c = cellfun(@(x) size(x,2), rates);                                         % Count the # of trains in each group
cc=max(c);                                                                  % Find the length of the largest group
t = cellfun(@(x) mean(x,2), bins, 'UniformOutput', false);                  % Find the mean time of each bin

figure
k=0;
for z=1:groups                                                              % For each group
    for zz=1:cc                                                             % for each train
        k=k+1;
        if zz<=c(z)
            subplot(groups,cc,k);
            plot(t{z},rates{z}(:,zz));                                      % Plot the firing rates of the group over time
            title(['Group ',num2str(z),', Firing Rate of Spike Train ',num2str(zz)]);
            xlabel('Time (sec)');
        end
    end
end
            
figure
for i = 1:groups                                                            % For each group
    subplot(groups,1,i);
    plot(t{z},PC1{i});                                                      % Plot the 1st PC over time
    title(['PC1 of group ',num2str(i)]);
    xlabel('Time (sec)');
    ylabel('PC1 of Firing Rate');
end