%% UNIFORM_DATASET generates a uniform dataset and writes it to a file. % % Discussion: % % This program is meant to be used interactively. It's also % possible to prepare a simple input file beforehand and use it % in batch mode. % % The program requests input values from the user: % % * NDIM, the spatial dimension, % * N, the number of points to generate, % * SEED, a seed for the random number generator. % % The program generates the data, writes it to the file % % uniform_NDIM_N.txt % % where "NDIM" and "N" are the numeric values specified by the user, % and then asks the user for more input. To indicate that no further % computations are desired, it is enough to input a nonsensical % value, such as -1. % % Modified: % % 14 September 2006 % % Author: % % John Burkardt % timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'UNIFORM_DATASET\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Generate a uniform pseudorandom dataset.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' This program is meant to be used interactively.\n' ); fprintf ( 1, ' It is also possible to prepare a simple input \n' ); fprintf ( 1, ' file beforehand and use it in batch mode.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' The program requests input values from the user:\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' * NDIM, the spatial dimension,\n' ); fprintf ( 1, ' * N, the number of points to generate,\n' ); fprintf ( 1, ' * SEED, a seed for the random number generator.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' The program generates the data, writes it to the file\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' uniform_NDIM_N.txt\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' where "NDIM" and "N" are the numeric values specified\n' ); fprintf ( 1, ' by the user, and then asks the user for more input.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' To indicate that no further computations are \n' ); fprintf ( 1, ' desired, it is enough to input a nonsensical value, \n' ); fprintf ( 1, ' such as -1.\n' ); while ( 1 ) fprintf ( 1, ' *\n' ); fprintf ( 1, ' *\n' ); fprintf ( 1, '* Ready to generate a new dataset:\n' ); fprintf ( 1, ' *\n' ); fprintf ( 1, ' *\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' NDIM is the spatial dimension.\n' ); fprintf ( 1, ' (Try ''2'' if you have no preference.)\n' ); fprintf ( 1, ' Any value less than 1 terminates execution.\n' ); ndim = []; ndim = input ( ' Enter NDIM: ' ); fprintf ( 1, ' User input NDIM = %d\n', ndim ); if ( ndim < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'UNIFORM_DATASET\n' ); fprintf ( 1, ' The input value of NDIM = %d\n', ndim ); fprintf ( 1, ' is interpreted as a request for termination.\n' ); fprintf ( 1, ' Normal end of execution.\n' ); break end fprintf ( 1, '\n' ); fprintf ( 1, ' N is the number of points.\n' ); fprintf ( 1, ' (Try ''25'' if you have no preference.)\n' ); fprintf ( 1, ' Any value less than 1 terminates execution.\n' ); n = []; n = input ( ' Enter N: ' ); fprintf ( 1, ' User input N = %d\n', n ); if ( n < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'UNIFORM_DATASET\n' ); fprintf ( 1, ' The input value of N = %d\n', n ); fprintf ( 1, ' is interpreted as a request for termination.\n' ); fprintf ( 1, ' Normal end of execution.\n' ); break end fprintf ( 1, '\n' ); fprintf ( 1, ' SEED is a seed for the random number generator.\n' ); fprintf ( 1, ' (Try 123456789 if you have no preference.)\n' ); fprintf ( 1, ' (A value of 0 or less terminates execution.)\n' ); seed = input ( ' Enter SEED: ' ); fprintf ( 1, '\n' ); fprintf ( 1, ' SEED = %d\n', seed ); if ( seed <= 0 ) fprintf ( 1, '\n' ); fprintf ( 1, 'UNIFORM_DATASET\n' ); fprintf ( 1, ' The nonpositive input value of SEED is interpreted\n' ); fprintf ( 1, ' as a request for termination.\n' ); fprintf ( 1, ' Normal end of execution.\n' ); end seed_init = seed; [ r, seed ] = r8mat_uniform_01 ( ndim, n, seed ); file_out_name = ... strcat ( 'uniform_', num2str ( ndim ), '_', num2str ( n ), '.txt' ); r8mat_uniform_write ( ndim, n, seed_init, r, file_out_name ); fprintf ( 1, '\n' ); fprintf ( 1, ' The data was written to the file "%s".\n', ... file_out_name ); end fprintf ( 1, '\n' ); timestamp;