[原创]Matlab生成随机数
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生成随机数函数
原文地址:利用matlab生成随机数函数 rand(n):生成0到1之间的n阶随机数方阵 rand(m,n):生成0到1之间的m×n的随机数矩阵 (现成的函数) betarnd:贝塔分布的随机数生成 ...
- [原创]Matlab之GUI生成EXE文件
近期因为项目需要,简化流程,写了一些Matlab程序,并配备上了GUI界面使其简单易用.然后问题来了,可移植性.使用Matlab生成EXE文件(可以封装很多的function),然后在一台安装有Mat ...
- Matlab生成Word--xdd
摘自<MATLAB统计分析与应用:40个案例分析>(谢中华老师著)P452页function CreatWord %利用Matlab生成word filespec_user = [pwd ...
- MATLAB生成exe脱离matlab运行可执行程序
https://blog.csdn.net/u013007900/article/details/53485204 侵权即删. ———————————————— 版权声明:本文为CSDN博主「小木匠_ ...
- matlab 生成.exe文件 转
本文链接:https://blog.csdn.net/qq_20823641/article/details/51863737 如何将MATLAB程序编译成独立可执行的程序?如何将编译好的独立可执行程 ...
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
- DotNet生成随机数的一些方法
在项目开发中,一般都会使用到“随机数”,但是在DotNet中的随机数并非真正的随机数,可在一些情况下生成重复的数字,现在总结一下在项目中生成随机数的方法. 1.随机布尔值: /// <summa ...
- Oracle中生成随机数的函数(转载)
在Oracle中的DBMS_RANDOM程序包中封装了一些生成随机数和随机字符串的函数,其中常用的有以下两个: DBMS_RANDOM.VALUE函数 该函数用来产生一个随机数,有两种用法: 1. 产 ...
- [转载]Matlab生成Word报告
最近在进行一批来料的检验测试,一个个手动填写报告存图片太慢了,就有了种想要使用Matlab在分析完后数据可以自动生成PDF报告的想法,于是就去网上搜索了相关的资料,发现Matlab中文论坛上有xiez ...
随机推荐
- [ 转载 ] kernel32.BaseThreadInitThunk
Edited by wap2k, 20 October 2014 - 07:52 PM. This function is called to start a Win32 thread. Its pu ...
- Url路径重写的原理
ASP.net的地址重写(URLRewriter)实现原理及代码示例 吴剑 2007-01-01 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian/ 概述 访问 ...
- AfxMessageBox和MessageBox区别
如果用MFC的话,请尽量使用afxmessagebox,因为这个全局的对话框最安全,也最方便. 但是在WIN32 SDK的情况下只能使用MESSAGEBOX. MessageBox()是Win3 ...
- 安卓APP测试验证点总结
最近较懒,加之闺女出生后记忆没完全恢复,总是忘东忘西,关于安卓APP测试的验证点还是总结一下,方便设计测试用例时查阅,也给各位博友参考! 1.除APP的正常功能点外,还有以下验证点: 安装/卸载(考虑 ...
- vs中使用openGL
一.准备工作 创建Empty Project,为了能够使用OpenGL的库函数,需要把相关的库连接到项目中: 1.首先添加库的路径 如上,可以把需要添加的include.lib放到一起比较方便管理 这 ...
- Salesforce 数据清洗
新系统上线后,需要导入历史数据,但是旧数据格式,数据缺失,数据错误,奇异值,属性归类与新系统有很大的gap.因此我们需要建立一套数据动态清洗规则给Salesforce系统,通过这些规则自动清洗导入数据 ...
- c++ 打印堆栈代码
namespace google {namespace glog_internal_namespace_ {void DumpStackTraceToString(std::string* stack ...
- 《SSM框架搭建》三.整合spring web
感谢学习http://blog.csdn.net/zhshulin/article/details/37956105#,还是修改了spring到最新的版本和接口开发示例 根据前一篇日志,已经有了myb ...
- Oracle中SYS_CONNECT_BY_PATH函数的使用
在Oracle中,SYS_CONNECT_BY_PATH函数主要作用是可以把一个父节点下的所有子节点通过某个字符进行区分,然后连接在一个列中显示. sys_connect_by_path(字段名, 2 ...
- php实现只保留mysql中最新1000条记录
这篇文章主要介绍了php实现只保留mysql中最新1000条记录的方法和相关示例及数据库结构,十分的全面,有需要的小伙伴可以参考下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...