Matlab 中有着丰富的随机数生成函数以应用于不同的情景,我一般使用生成随机的 1~N 的整数,但是之前了解的只有 rand 函数,其生成主要为 0 ~ 1 之间的随机数,但是和所预想的有差异。在此进行进行了help 指令,之后了解到了 randi 函数,并初步学会使用,在此做一个记录。

rand 函数

rand 函数是生产 0 ~ 1 的随机数,rand(N) 为生产一个 N 行 N 列的随机数矩阵,rand(M, N) 为生成一个 M 行 N 列的随机数矩阵。以下为一些示例。

>> rand(3)

ans =

0.8147 0.9134 0.2785

0.9058 0.6324 0.5469

0.1270 0.0975 0.9575

>> rand(2, 3)

ans =

0.9649 0.9706 0.4854

0.1576 0.9572 0.8003

在 help rand 后,我们可以观察其解释说明。

>> help rand

rand Uniformly distributed pseudorandom numbers.

R = rand(N) returns an N-by-N matrix containing pseudorandom values drawn

from the standard uniform distribution on the open interval(0,1). rand(M,N)

or rand([M,N]) returns an M-by-N matrix. rand(M,N,P,...) or

rand([M,N,P,...]) returns an M-by-N-by-P-by-... array. rand returns a

scalar. rand(SIZE(A)) returns an array the same size as A.

Note: The size inputs M, N, P, ... should be nonnegative integers.

Negative integers are treated as 0.

R = rand(..., 'double') or R = rand(..., 'single') returns an array of

uniform values of the specified class.

The sequence of numbers produced by rand is determined by the settings of

the uniform random number generator that underlies rand, RANDI, and RANDN.

Control that shared random number generator using RNG.

通过最后其提示的 See also, 我们可以观看其他和随机数有关的函数,看有没有合适的函数。

See also randi, randn, rng, RandStream, RandStream/rand,

sprand, sprandn, randperm.

randi 函数

产生 1 ~ NUM 的随机整数,NUM 可调整。其中 NUM 作为一个输入的参数。randi(MAX, N) 产生一个最大值为 MAX 的 N 行 N 列的整数矩阵,randi(MAX, M, N) 产生一个最大值为 MAX 的 M 行 N 列的整数矩阵。以下为一些示例。

>> randi(5, 6)

ans =

1 1 5 3 1 1

2 5 2 1 2 4

1 5 1 1 2 4

1 3 4 5 5 4

2 3 2 5 1 3

3 2 2 3 1 3

>> randi(5, 3, 9)

ans =

2 4 4 5 3 3 4 5 5

4 1 4 4 3 3 4 3 5

1 2 1 3 2 5 2 2 3

在 help randi 后,我们可以观察其解释说明。

>> help randi

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 arrays returned by randi may contain repeated integer values. This

is sometimes referred to as sampling with replacement. To get unique

integer values, sometimes referred to as sampling without replacement,

use RANDPERM.

The sequence of numbers produced by randi is determined by the settings of

the uniform random number generator that underlies RAND, RANDN, and randi.

randi uses one uniform random value to create each integer random value.

Control that shared random number generator using RNG.

matlab逆变换法产生随机数_[原创]Matlab 生成随机数相关推荐

  1. java 生成随机数_不会生成随机数?我们来看看java生成随机数的10种方法

    1.引言 本文将探讨用 Java 生成随机数的不同方法. 2.Java API Java API 提供了几种随机数生成方法.让我们一起来了解一下. 2.1.java.lang.Math Math 类中 ...

  2. R语言使用rnorm函数生成正态分布随机数、自定义指定生成随机数的个数、均值、方差

    R语言使用rnorm函数生成正态分布随机数.自定义指定生成随机数的个数.均值.方差 目录 R语言使用rnorm函数生成正态分布随机数.自定义指定生成随机数的个数.均值.方差 R 语言特点 R语言使用r ...

  3. matlab逆变换法产生随机数_信号处理——生成给定分布随机数

    作者:桂. 时间:2017-03-12  19:31:55 前言 本文是曲线拟合与分布拟合一文的插曲,进行分布拟合时,碰到一个问题是,如何指定分布的随机数呢?本文主要包括: 1)连续型随机数: 2)离 ...

  4. matlab舍选法编程,利用舍选抽样法生成随机数.pdf

    利用舍选抽样法生成随机数.pdf 2013年11月 重庆师范大学学报(自然科学版) Nov-2013 笙!!鲞笙!塑 !!!:!!!!!:! !!::!!!!!呈!!竺!竺!些!:竺!!!!!!:!! ...

  5. matlab中表示拉普拉斯分布_拉普拉斯分布的随机数

    一.功能 产生拉普拉斯分布的随机数. 二.方法简介 1.产生随机变量的组合法 将分布函数\(F(x)\)分解为若干个较为简单的子分布函数的线性组合 \[F(x)=\sum_{i=1}^{K}p_{i} ...

  6. 基于matlab的脑瘤mr图像处理_基于Matlab GUI的医学图像处理课程虚拟实验平台设计...

    论文写作指导:请加QQ229366758 摘 要:针对医学生工程技术缺乏的状况,分析医学生学习医学图像处理存在的困难,提出利用Matlab图像处理工具和简单的GUI界面,设计和构建包含医学图像处理教学 ...

  7. matlab需要多大运存_提高matlab运行效率

    用过Matlab的人都知道,Matlab是一种解释性语言,存在计算速度慢的问题,为了提高程序的运行效率,matlab提供了多种实用工具及编码技巧. 1. 循环矢量化 Matlab是为矢量和矩阵操作而设 ...

  8. matlab 创建批量文件夹_初识MATLAB

    1. MATLAB是什么? MATLAB,是"matrix laboratory"的缩写形式,意思是矩阵实验室.MATLAB是在1984年由一个大学生把数学课的教学课件重新编程设计 ...

  9. mysql语句随机数_程序生成随机数与SQL语句生成随机数

    随机数可以通过程序生成,也可以通过SQL语句生成.通过程序生成随机数时一般采用硬件的编号+时间作为种子,这种方法在瞬间插入数据库N条数据的时候会影响随机数的效果,生成很多相邻的插入值相同.所以频繁插入 ...

  10. python产生5个随机数_Python和numpy生成随机数

    http://blog.csdn.net/pipisorry/article/details/39086463 随机数种子 要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成 ...

最新文章

  1. wcf http 返回图片
  2. 什么是物联网?—Vecloud 微云
  3. 【目标检测】RCNN算法详解
  4. MySQL遇到check the manual that corresponds to your MySQL server version for the right syntax错误
  5. 【转】DICOM入门(一)——语法
  6. 防止U盘中病毒的小技巧
  7. Mac实用软件及功能吐血总结
  8. 塔设备设计手册_强烈推荐必备资料—化工设备设计手册 (上、下卷全)
  9. 记录甘肃机顶盒MG101_U2破解之路的辛酸历程
  10. LumaQQ开发文档
  11. java从入门到放弃教程(一) 想转行的看过来
  12. 编译一个.cpp文件的过程
  13. Python中格式化操作漂亮打印文件的读取和写入
  14. 不同型号的二极管模块并联_原来我不懂二极管…
  15. Proe转Solidworks
  16. 阿米洛蓝牙连接教程_游戏手柄还不会使用?来这教你,轻松搞定游戏手柄连接问题...
  17. 服务器安全证书更新失败怎么回事,手机安全证书更新失败怎么办
  18. ubuntu设置共享文件夹
  19. 2021-04-21
  20. 2021-12-3 温故而知新-JavaScript隐式转换

热门文章

  1. k8s---adm构建
  2. python can通信_使用python来调用CAN通讯的DLL实现方法
  3. 数学模型预测模型_改进著名的nfl预测模型
  4. 小程序快递单号查询接口物流助手对接指南
  5. element tabs label 插槽
  6. 浏览器解析渲染页面过程
  7. teensy 制作键盘 linux,kbfirmware使用教程——以制作小太刀TEX Kodachi键盘为例
  8. Nginx反向代理后无法获取header带下划线的头信息
  9. Off the coast 将图片放入Markdown!
  10. Tomcat8+Redis集群解决会话共享