function [str,sel]=strChoose(lstr,prob,default)
% strChoose <String Choose>
% Usage:: [str]=strChoose(lstr,prob[uniform],default[{''}])
%
% Choose a string from a cell list of strings

% revision history:
% 01/28/94 Mark D. Shattuck <mds> strChoose.m
% 10/22/11 update header

%% Parse Input
[N Ns]=size(lstr);
if(N==1 || Ns==1)
  Ns=max(Ns,N);
end
if(~exist('prob','var') || isempty(prob))
  if(N==2)
    prob=[lstr{2,:}];
    lstr=lstr(1,:);
  else
    prob=ones(1,Ns);
  end
end

if(~exist('default','var') || isempty(default))
	default={''};
end

%% Main

if(~iscell(lstr)) 
  if(strcmp(lstr,'')==1)
    lstr=default;
  else
    lstr={lstr};
  end
end

prob=cumsum(prob/sum(prob));
sel=diff([0 prob>rand])==1;
str=lstr{sel};


