急求MATLAB的randi函数源代码,我的7.1没有,谢谢谢谢

 我来答
百度网友39533e909
2011-06-17 · TA获得超过1584个赞
知道小有建树答主
回答量:195
采纳率:0%
帮助的人:148万
展开全部
%RANDI Pseudorandom integers from a uniform discrete distribution.
% R = RANDI(IMAX,N) returns an N-by-N matrix containing pseudorandom
% integer values drawn from the discrete uniform distribution on 1:IMAX.
% RANDI(IMAX,M,N) or RANDI(IMAX,[M,N]) returns an M-by-N matrix.
% RANDI(IMAX,M,N,P,...) or RANDI(IMAX,[M,N,P,...]) returns an
% M-by-N-by-P-by-... array. RANDI(IMAX) returns a scalar.
% RANDI(IMAX,SIZE(A)) returns an array the same size as A.
%
% R = RANDI([IMIN,IMAX],...) returns an array containing integer
% values drawn from the discrete uniform distribution on IMIN:IMAX.
%
% Note: The size inputs M, N, P, ... should be nonnegative integers.
% Negative integers are treated as 0.
%
% R = RANDI(..., CLASSNAME) returns an array of integer values of class
% CLASSNAME.
%
% The sequence of numbers produced by RANDI is determined by the internal
% state of the uniform pseudorandom number generator that underlies RAND,
% RANDI, and RANDN. RANDI uses one uniform value from that default
% stream to generate each integer value. Control the default stream using
% its properties and methods. See RANDSTREAM for details about the
% default stream.
%
% Resetting the default stream to the same fixed state allows computations
% to be repeated. Setting the stream to different states leads to unique
% computations, however, it does not improve any statistical properties.
% Since MATLAB uses the same state each time it starts up, RAND, RANDN, and
% RANDI will generate the same sequence of numbers in each session unless
% the state is changed.
%
% Examples:
%
% Generate integer values from the uniform distribution on the set 1:10.
% r = randi(10,100,1);
%
% Generate an integer array of integers drawn uniformly from 1:10.
% r = randi(10,100,1,'uint32');
%
% Generate integer values drawn uniformly from -10:10.
% r = randi([-10 10],100,1);
%
% Save the current state of the default stream, generate 5 integer
% values, restore the state, and repeat the sequence.
% defaultStream = RandStream.getDefaultStream;
% savedState = defaultStream.State;
% i1 = randi(10,1,5)
% defaultStream.State = savedState;
% i2 = randi(10,1,5) % contains exactly the same values as i1
%
% Replace the default stream with a stream whose seed is based on CLOCK, so
% RANDI will return different values in different MATLAB sessions. NOTE: It
% is usually not desirable to do this more than once per MATLAB session.
% RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(100*clock)));
% randi(10,1,5)
%
% See also RAND, RANDN, RANDSTREAM, RANDSTREAM/RANDI, RANDSTREAM.GETDEFAULTSTREAM.

% Copyright 2008 The MathWorks, Inc.
% $Revision: 1.1.6.2 $ $Date: 2008/09/13 06:57:04 $
% Built-in function.
匿名用户
2014-02-09
展开全部
function matrix=randi(num,a,b)
vector=randsample(num,a*b);
matrix=reshape(vector,a,b);
end

将上述代码保存为randi.m文件。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式