function setrandstate(flag) <flag> (optional) is 0 means seed to 0 1 means seed to sum(100*clock) {N} means seed to N default: 1. induce randomness by setting the state of rand and randn. example: setrandstate;
0001 function setrandstate(flag) 0002 0003 % function setrandstate(flag) 0004 % 0005 % <flag> (optional) is 0006 % 0 means seed to 0 0007 % 1 means seed to sum(100*clock) 0008 % {N} means seed to N 0009 % default: 1. 0010 % 0011 % induce randomness by setting the state of rand and randn. 0012 % 0013 % example: 0014 % setrandstate; 0015 0016 if ~exist('flag','var') || isempty(flag) 0017 flag = 1; 0018 end 0019 if iscell(flag) 0020 seed0 = flag{1}; 0021 elseif flag==0 0022 seed0 = 0; 0023 else 0024 seed0 = sum(100*clock); 0025 end 0026 rand('state',seed0); 0027 randn('state',seed0);