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

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