
function [] = barmerged_plot(barGenMerged,barcodeGen,i,lab) 

if isfield(barGenMerged{i},'alignedBars')
h_main=plot(1:length(barGenMerged{i}.rawBitmask(barGenMerged{i}.rawBitmask==1)), barGenMerged{i}.rawBarcode(barGenMerged{i}.rawBitmask==1));
legendEntries={};
legendhandles = [];
legendhandles(1)=h_main;
legendEntries{1} =strcat(['Merged barcode']);%   %, num2str(barGenMerged{i}.score)]);
    
hold on
  for h=1:length(barGenMerged{i}.idx)
h_main=plot(1:length(barGenMerged{i}.alignedBars),barGenMerged{i}.alignedBars(h,:)+nanmean(nanmean(barGenMerged{i}.alignedBars))/3);
    
  
    entryStr = strcat([barcodeGen{1,barGenMerged{i}.idx(h)}.name]);
    entryStr = strrep(entryStr, '_', '\_');
    legendEntries{end+1} = entryStr;
    legendhandles(end+1) = h_main;
  end
%add labels with actual names

%text(200,1200,num2str(barGenMerged{end-i}.score))

%store all X and Y coordinates of each label in XT and YT
%store all text labels in LT
%Use Text correctly
 % if lab
 %    xT=[200];
 %    yT=[mean(barGenMerged{i}.rawBarcode)];
 %    LT={num2str(barGenMerged{i}.score)};
 % 
 %    text(xT,yT,LT,'Color')
 % end

legend(legendhandles, legendEntries, 'Location', 'southoutside', 'Interpreter', 'latex','FontSize', 12);

end
end