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