wolffd@0: function datwrite(filename, x, t) wolffd@0: %DATWRITE Write data to ascii file. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % DATWRITE(FILENAME, X, T) takes a matrix X of input vectors and a wolffd@0: % matrix T of target vectors and writes them to an ascii file named wolffd@0: % FILENAME. The file format is as follows: the first row contains the wolffd@0: % string NIN followed by the number of inputs, the second row contains wolffd@0: % the string NOUT followed by the number of outputs, and the third row wolffd@0: % contains the string NDATA followed by the number of data vectors. wolffd@0: % Subsequent lines each contain one input vector followed by one output wolffd@0: % vector, with individual values separated by spaces. wolffd@0: % wolffd@0: % See also wolffd@0: % DATREAD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: nin = size(x, 2); wolffd@0: nout = size(t, 2); wolffd@0: ndata = size(x, 1); wolffd@0: wolffd@0: fid = fopen(filename, 'wt'); wolffd@0: if fid == -1 wolffd@0: error('Failed to open file.') wolffd@0: end wolffd@0: wolffd@0: if size(t, 1) ~= ndata wolffd@0: error('x and t must have same number of rows.'); wolffd@0: end wolffd@0: wolffd@0: fprintf(fid, ' nin %d\n nout %d\n ndata %d\n', nin , nout, ndata); wolffd@0: for i = 1 : ndata wolffd@0: fprintf(fid, '%13e ', x(i,:), t(i,:)); wolffd@0: fprintf(fid, '\n'); wolffd@0: end wolffd@0: wolffd@0: flag = fclose(fid); wolffd@0: if flag == -1 wolffd@0: error('Failed to close file.') wolffd@0: end wolffd@0: