function sparse2labels(Y, filename)

f = fopen(filename, 'w');

for i = 1:size(Y, 1)
  idx = find(Y(i,:));
  if length(idx)>1
    fprintf(f, '%d,', idx(1:end-1));
  end
  if length(idx)>0
    fprintf(f, '%d', idx(end));
  end
  fprintf(f, '\n');
end

fclose(f);