home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS1.DI$ / VARYRAND.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.2 KB  |  40 lines

  1. % function out = varyrand(rdim,cdim,nindv,ivflg)
  2. %
  3. %  Create a random VARYING matrix, with a specified number of
  4. %  rows RDIM, columns CDIM, and independent variable values NINDV.
  5. %  The default value for IVFLG is 0 which sorts the positive,
  6. %  random independent variables to be monotonically increasing. 
  7. %  If IVFLG is set to a nonzero value, then the independent variable's
  8. %  values are 1:NINDV.
  9. %
  10. %   See also: CRAND, RAND, SYSRAND, and RANDEL.
  11.  
  12.  function out = varyrand(rdim,cdim,nindv,ivflg)
  13.  if nargin < 3
  14.    disp(['usage: out = varyrand(rdim,cdim,nindv)']);
  15.  else
  16.    if nargin == 3
  17.      ivflg = 0;
  18.    end
  19.    if min([rdim cdim nindv]) <= 0
  20.      error('dimensions should be positive')
  21.      return
  22.    elseif ceil([rdim cdim nindv]) == floor([rdim cdim nindv])
  23.      out = zeros(rdim*nindv+1,cdim+1);
  24.      out(rdim*nindv+1,cdim+1) = inf;
  25.      out(rdim*nindv+1,cdim) = nindv;
  26.      if ivflg == 0
  27.        out(1:nindv,cdim+1) = sort(exp(rand(nindv,1)));
  28.      else
  29.        out(1:nindv,cdim+1) = (1:nindv)';
  30.      end
  31.      out(1:nindv*rdim,1:cdim) = rand(nindv*rdim,cdim);
  32.    else
  33.      error('dimensions should be integers')
  34.      return
  35.    end
  36.  end
  37.  
  38. %
  39. % Copyright MUSYN INC 1991,  All Rights Reserved
  40.