%function ans = writeMatrix(X,filename,labels);
%
%Writes matrix in the subdirectory ResultMatrices/
% Labels is a cell array containing the column labels 
% labels = {'label1' 'label2' 'label3'};
% To skip labels use empty string: writeMatrix(X,fn,'')

function ans = writeMatrix(X,filename,labels);

%fname = ['Result_textfiles/' filename];
fname = filename;
fid=fopen(fname,'w');

for l = 1:length(labels)
     s = labels{l};
   fprintf(fid, '%s\t', s);
end 
if (l>0) 
   fprintf(fid, '\n');
end

[sz1,sz2] = size(X);
for i =1:sz1
        for j = 1:sz2
              fprintf(fid, '%f\t ', X(i,j));  
        end 
        fprintf(fid, '\n');
end
fclose('all'); 
