annotate toolboxes/FullBNT-1.0.7/netlab3.3/datwrite.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function datwrite(filename, x, t)
wolffd@0 2 %DATWRITE Write data to ascii file.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 %
wolffd@0 6 % DATWRITE(FILENAME, X, T) takes a matrix X of input vectors and a
wolffd@0 7 % matrix T of target vectors and writes them to an ascii file named
wolffd@0 8 % FILENAME. The file format is as follows: the first row contains the
wolffd@0 9 % string NIN followed by the number of inputs, the second row contains
wolffd@0 10 % the string NOUT followed by the number of outputs, and the third row
wolffd@0 11 % contains the string NDATA followed by the number of data vectors.
wolffd@0 12 % Subsequent lines each contain one input vector followed by one output
wolffd@0 13 % vector, with individual values separated by spaces.
wolffd@0 14 %
wolffd@0 15 % See also
wolffd@0 16 % DATREAD
wolffd@0 17 %
wolffd@0 18
wolffd@0 19 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 20
wolffd@0 21 nin = size(x, 2);
wolffd@0 22 nout = size(t, 2);
wolffd@0 23 ndata = size(x, 1);
wolffd@0 24
wolffd@0 25 fid = fopen(filename, 'wt');
wolffd@0 26 if fid == -1
wolffd@0 27 error('Failed to open file.')
wolffd@0 28 end
wolffd@0 29
wolffd@0 30 if size(t, 1) ~= ndata
wolffd@0 31 error('x and t must have same number of rows.');
wolffd@0 32 end
wolffd@0 33
wolffd@0 34 fprintf(fid, ' nin %d\n nout %d\n ndata %d\n', nin , nout, ndata);
wolffd@0 35 for i = 1 : ndata
wolffd@0 36 fprintf(fid, '%13e ', x(i,:), t(i,:));
wolffd@0 37 fprintf(fid, '\n');
wolffd@0 38 end
wolffd@0 39
wolffd@0 40 flag = fclose(fid);
wolffd@0 41 if flag == -1
wolffd@0 42 error('Failed to close file.')
wolffd@0 43 end
wolffd@0 44