%% Loads a dot-product matrix and converts the variable PHI into a format
%% readble by libsvm routines

function convert_Phi_to_SVMinput(Phi, n, m, labels, training, test)
    
    % create training data file
    f=fopen(training,'w');
    for i=1:n;
        fprintf(f,[num2str(labels(i))]);
    for j=1:n;
        fprintf(f,[' ' num2str(j) ':' num2str(Phi(i,j))]);end; fprintf(f,'\n');
    end;
    fclose(f);
    
    % create testing data file
    f=fopen(test,'w');
    for i=n+1:n+m;
        fprintf(f,[num2str(labels(i))]);
    for j=1:n;
        fprintf(f,[' ' num2str(j) ':' num2str(Phi(i,j))]);end; fprintf(f,'\n');
    end;
    fclose(f);
end