function plotted = generateFigs(path, pattern, ymax, xmax, labels)

if nargin < 3
    ymax = 5000;
end
if nargin < 4
    xmax = 500;
end

% Create figure
figure1 = figure('Position', [1500, 300, 350, 250]);

% Create axes
axes1 = axes('Parent',figure1);
ylim(axes1,[0 ymax]);
xlim(axes1,[0 xmax]);
box(axes1,'on');
hold(axes1,'all');

files = dir(path);
pnum = 0;
for i = 1: numel(files)    
    currfile = files(i).name;
    if numel(regexp(currfile, pattern)) > 0
        pnum = pnum+1;
        currpath = fullfile(path, currfile);
        currm = dlmread(currpath);
        
        x_vals = currm(1,:);
        y_vals = median(currm(2:size(currm),:));
%         y_vals = quantile(currm(2:size(currm),:), 0.95);
%         y_vals = mean(currm(2:size(currm),:));
        plotted = [x_vals; y_vals];
        e_vals_low = quantile(currm(2:size(currm),:), 0.25);
        e_vals_high = quantile(currm(2:size(currm),:), 0.75);
%          e_vals = std(currm(2:size(currm),:));
%          boxplot(currm(2:size(currm),:), 'position', x_vals, 'labels', x_vals, 'Parent', axes1, 'plotstyle', 'compact');
%          plot(x_vals, y_vals);
%         break

%          if nargin < 5
%              h = errorbar(x_vals, y_vals, e_vals_low, e_vals_high, 'Parent', axes1, 'DisplayName', currfile);
%          else
%              h = errorbar(x_vals, y_vals, e_vals_low, e_vals_high, 'Parent', axes1, 'DisplayName', labels{pnum});
%          end
%          colorLineStyle(h(1), pnum);
         
        if nargin < 5
            p = plot(x_vals, y_vals, 'DisplayName', currfile, 'Parent', axes1);
        else
            p = plot(x_vals, y_vals, 'DisplayName', labels{pnum}, 'Parent', axes1);
        end
        colorLineStyle(p(1), pnum);
    end
end


% Create xlabel
xlabel({'Query Arrival Rate (queries/sec)'});

% Create ylabel
ylabel({'Median Processing Time (ms)'});

% Create title
%title({'ClueWeb no dup 1 week'});

% Create legend
leg = legend(axes1,'show');
set(leg,'PlotBoxAspectRatio',[1 0.6 1]);
end