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