matlab 中的随机函数 | 您所在的位置:网站首页 › matlab随机函数有哪些 › matlab 中的随机函数 |
Matlab 中的几个随机函数 -randperm,sort,rand,randint Matlab 自带函数 randperm(n) 产生 1 到 n 的整数的无重复的随机排列, 利用它就可以得到无重复的随机数。
function p = randperm(n);
%RANDPERM Random permutation.
% RANDPERM(n) is a random permutation of the integers from 1 to n.
% For example, RANDPERM(6) might be [2 4 5 6 1 3].
%
% Note that RANDPERM calls RAND and therefore changes RAND's state. %
% See also PERMUTE. % Copyright 1984-2002 The MathWorks, Inc.
% $Revision: 5.10 $ $Date: 2002/04/09 00:26:14 $
[ignore,p] = sort(rand(1,n));
原理:
|
CopyRight 2018-2019 实验室设备网 版权所有 |