function buttonexportLIB(hObject, eventdata, emptybutton, Button, Axes, t, Info, parent, type)

data = get(emptybutton,'UserData');

if isfield(data,'selectednr')
    if type == 1
        FilterSpec = '*.txt';
        DialogTitle = 'Export the selected spectrum as *.txt file';
        DefaultName = [data.lib(data.selectednr).name,'.txt'];
    else
        FilterSpec = '*.mat';
        DialogTitle = 'Export the selected spectrum as *.mat file';
        DefaultName = [data.lib(data.selectednr).name,'.mat'];
    end
    
    
    [FileName,PathName,FilterIndex] = uiputfile(FilterSpec,DialogTitle,DefaultName);
    
    if FilterIndex >= 1
        if size(data.lib(data.selectednr).x,1) > size(data.lib(data.selectednr).x,2)
            x = data.lib(data.selectednr).x;
        else
            x = data.lib(data.selectednr).x';
        end
        if size(data.lib(data.selectednr).a,1) > size(data.lib(data.selectednr).a,2)
            a = data.lib(data.selectednr).a;
        else
            a = data.lib(data.selectednr).a';
        end
        
        if type == 1
            dlmwrite([PathName, FileName],[x, a],'precision','%e','delimiter',',');
        else
            save([PathName, FileName],'x', 'a');
        end
    end
end
