function basis_write ( file_out_name, m, n, s, u, comment ) %% BASIS_WRITE writes a basis vector to a file. % % Modified: % % 15 May 2007 % % Author: % % John Burkardt % % Parameters: % % Input, string FILE_OUT_NAME, the name of the file to write. % % Input, integer M, the number of data components. % % Input, integer N, the number of data items. % % Input, real S, the associated singular value. % % Input, real U(M,N), the data values. % % Input, logical COMMENT, is TRUE if comments are to be included. % file_out_unit = fopen ( file_out_name, 'wt' ); if ( file_out_unit < 0 ) fprintf ( 1, '\n' ); fprintf ( 1, 'BASIS_WRITE - Error!\n' ); fprintf ( 1, ' Could not open the output file.\n' ); error ( 'BASIS_WRITE - Error!' ); return; end if ( comment ) string = timestring; fprintf ( file_out_unit, '# %s\n', file_out_name ); fprintf ( file_out_unit, '# created by BASIS_WRITE.M\n' ); fprintf ( file_out_unit, '# part of SVD_BASIS.M\n' ); fprintf ( file_out_unit, '#\n' ); fprintf ( file_out_unit, '# Created on %s\n', string ); fprintf ( file_out_unit, '#\n' ); fprintf ( file_out_unit, '# Number of components M = %d\n', m ); fprintf ( file_out_unit, '# Number of items N = %d\n', n ); fprintf ( file_out_unit, '# Singular value S = %f\n', s ); fprintf ( file_out_unit, '#\n' ); end k = 0; for j = 1 : n for i = 1 : m k = k + 1; fprintf ( file_out_unit, '%14f ', u(k) ); end fprintf ( file_out_unit, '\n' ); end fclose ( file_out_unit );