function exportHelper(fig, option)

name = getFigureName(fig);
filter = {'*.jpg;*.jpeg', 'JPEG Files (*.jpg, *.jpeg)';...
 '*.png', 'PNG Files (*.png)';...
 '*.tif;*.tiff','TIFF Files(*.tif, *.tiff)';...
 '*.pdf','PDF Files (*.pdf)';...
 '*.eps','Encapsulated PostScript (*.eps)'};
title = 'Export Figure';

% If this is a specific type of export, build the exact filter
% and title for the dialog
if ~isempty(option)
    filter = {['*.', option], [upper(option) ' Files (*.' option ')'] };
    title = ['Export ' upper(option) ' File'];
end

[file,path] = uiputfile(filter, title, name);

% The user selected a file name and path
if ~isequal(file,0) && ~isequal(path,0)
    exportgraphics(fig, [path file]);
end

end

function name = getFigureName(fig)
    name = fig.Name;
    
    if isempty(name)
        name = fig.Tag;
    end
    
    if isempty(name)
       name = ['Figure_' num2str(fig.Number)]; 
    end    
end