function [] = create_hist_vec(B_cat, period, winltimes, ptimes, B_output, quietwin_index, IARwin, lwinsvec, winpeaksrmstime, s, quietwin, IARwins)

global fntsize res xsize ysize lmarg bmarg widthv heightv xstr titlestr fstr

global fs
% Unmatched B or matched
% unmatched
if strcmp(B_cat,'unmatched')
    % Whole day
    if strcmp(period,'day')
        % Need to concatonate the B above threshold in each time interval into
        % one large vector
        hist_vec = [];
        for i = 1:length(winltimes)
            hist_vec = [hist_vec; abs(B_output(winpeaksrmstime{i}{1}))];
        end
        
        f1=figure('Position', [0 0 s(3) s(4)]);%('Position', [0 0 s(3) s(4)]); % New figure
        
        histogram(hist_vec,20);
        % Time intervals
    elseif strcmp(period,'intervals')
        timeindexvec = [quietwin_index, 2*IARwin(1)+1:2*IARwin(2)];
        f1=figure('Position', [0 0 s(3) s(4)]);%('Position', [0 0 s(3) s(4)]); % New figure
        for i = 1:length(timeindexvec)
            hist_vec = abs(B_output(winpeaksrmstime{timeindexvec(i)}{1}));
            ax(i)=subplot(3,4,i);
            histogram(hist_vec);
            xlabel('abs(B)','FontSize',15);
            ylabel('N','FontSize',15);
            if i == 1
                title({strcat('Quiet (~',num2str(round((quietwin(1)/(fs*3600))/IARwin(3))*IARwin(3)),'-',num2str(round((quietwin(2)/(fs*3600))/IARwin(3))*IARwin(3)),' UTC)')}, 'fontsize', fntsize, 'fontname', 'helvetica'); % label the axes
            else
                title({strcat('IAR (~',num2str(IARwins(i-1)/(fs*3600)),'-',num2str(IARwins(i)/(fs*3600)),' UTC)')}, 'fontsize', fntsize, 'fontname', 'helvetica'); % label the axes
            end
        end
        
        linkaxes(ax,'xy')
        
    end
elseif strcmp(B_cat,'matched')
    % Matched B
    if strcmp(period,'day')
        % Need to concatonate the B above threshold in each time interval into
        % one large vector
        hist_vec = [];
        for i = 1:length(winltimes)
            hist_vec = [hist_vec; abs(B_output(ptimes{i,1}))];
        end
        
        f1=figure('Position', [0 0 s(3) s(4)]);%('Position', [0 0 s(3) s(4)]); % New figure
        
        histogram(hist_vec,20);
        % Time intervals
    elseif strcmp(period,'intervals')
        timeindexvec = [quietwin_index, 2*IARwin(1)+1:2*IARwin(2)];
        f1=figure('Position', [0 0 s(3) s(4)]);%('Position', [0 0 s(3) s(4)]); % New figure
        for i = 1:length(timeindexvec)
            hist_vec = abs(B_output(ptimes{timeindexvec(i),1}));
            ax(i)=subplot(3,4,i);
            histogram(hist_vec);
            xlabel('Matched abs(B)','FontSize',15);
            ylabel('N','FontSize',15);
            if i == 1
                title({strcat('Quiet (~',num2str(round((quietwin(1)/(fs*3600))/IARwin(3))*IARwin(3)),'-',num2str(round((quietwin(2)/(fs*3600))/IARwin(3))*IARwin(3)),' UTC)')}, 'fontsize', fntsize, 'fontname', 'helvetica'); % label the axes
            else
                title({strcat('IAR (~',num2str(IARwins(i-1)/(fs*3600)),'-',num2str(IARwins(i)/(fs*3600)),' UTC)')}, 'fontsize', fntsize, 'fontname', 'helvetica'); % label the axes
            end
        end
        
        linkaxes(ax,'xy')
        
    end
end
end