% function out = randel(blk,nrm)
%
%   Generates a random, block structured perturbation 
%   with specified norm (e.g. max singular value). The 
%   block structure is specified by the argument BLK,
%   and the norm is specified by the argument NRM.
%
%   See also: CRAND, DYPERT, and SYSRAND.

function  out = randel(blk,nrm,rflg)
 if nargin < 2
   disp('usage: pert = randel(blk,nrm)')
   return
 end
 [nblk,dum] = size(blk);
 blkp = ptrs(blk);
 out = zeros(blkp(nblk+1,1)-1,blkp(nblk+1,2)-1);
 for i=1:nblk
   if blk(i,2) == 0;
     delta = crand(1);
     if nargin == 3
       delta = real(delta);
     end
     delta = nrm*delta/abs(delta);
     deltab = delta*eye(blk(i,1));
   else
     delta = crand(blk(i,1),blk(i,2));
     if nargin == 3
       delta = real(delta);
     end
     deltab = nrm*delta/(norm(delta));
   end
   out(blkp(i,1):blkp(i+1,1)-1,blkp(i,2):blkp(i+1,2)-1) = deltab;
 end
%
% Copyright MUSYN INC 1991,  All Rights Reserved
