matlab函数之随机函数-randperm,sort,rand,randint
文章来源:http://blog.sina.com.cn/wangjiaye
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));
原理:
1. rand(1, n)产生1行n列的0-1之内的随机数矩阵。
2. sort()把这个矩阵排序,返回的ignore是排序后的序列,p是排序后的序列的各数原来的索引,这个索引肯定是随机的,而且是在1到n间无重复的整数。
附:《Matlab中的几个随机函数》
rand
rand(n):生成0到1之间的n阶随机数方阵
rand(m,n):生成0到1之间的m×n的随机数矩阵
randint
randint(m,n,[1 N]):生成m×n的在1到N之间的随机整数矩阵,其效果与randint(m,n,N+1)相同。
>> randint(3,4,[1 10])
ans =
5 7 4 10
5 1 2 7
8 7 8 6
>> randint(3,4,11)
ans =
10 9 6 9
5 10 8 9
10 0 2 6
randperm
randperm(n):产生一个1到n的随机顺序。
>> randperm(10)
ans =
6 4 8 9 3 5 7 10 2 1
matlab函数之随机函数-randperm,sort,rand,randint相关推荐
- mysql newid函数_sql随机函数newID()和RAND()详解
sql 随机函数newid()和rand()详解 * from northwind..orders order by newid() 下者效率要高些 select top 10 *,newid() a ...
- matlab 函数 c++ 复写之randperm
最近在写matlab代码转c++,会遇到一些重写的函数. 复写首先要了解randperm函数在matlab中的实现机理. 以下是函数原定义: function p = randperm(n); %RA ...
- matlab2c使用c++实现matlab函数系列教程-sort函数
全栈工程师开发手册 (作者:栾鹏) matlab2c动态链接库下载 matlab库函数大全 matlab2c基础教程 matlab2c开发全解教程 matlab2c调用方法: 1.下载动态链接库 2. ...
- matlab函数 randperm()的用法
randperm()函数用法 随机函数 语法: p = randperm(n) p = randperm(n,k) 语法描述: p = randperm(n) 返回一行包含从1到n的整数. > ...
- matlab2c使用c++实现matlab函数开发配置全解
全栈工程师开发手册 (作者:栾鹏) github: https://github.com/data-infra/matlab2c matlab2c动态链接库下载 matlab库函数大全 matlab2 ...
- MATLAB函数大全 .
http://pleasaunce.blog.sohu.com/94162301.html 网上看到的,很珍贵,怕人家删了,就自己考过来了 附录1 常用命令 附录1.1 管理用命令 函数名 功能描 ...
- MATLAB函数汇总
Matlab 函数参数汇总 MATLAB函数参考 附录1.1 管理用命令 函数名 功能描述 函数名 功能描述 addpath 增加一条搜索路径 rmpath 删除一条搜索路径 demo 运行Matla ...
- MATLAB 函数大全
附录1 常用命令 附录1.1 管理用命令 函数名 功能描述 函数名 功能描述 addpath 增加一条搜索路径 rmpath 删除一条搜索路径 demo 运行Matlab演示程序 type 列出.M文 ...
- csapi matlab,Matlab函数csapi与papi的区别是什么
2010-05-23 回答 matlab有多少api函数,因为数量很多,而且不同版本的函数数量也或许不一样,因为会把常用的需求去添加成新的api函数,不完全统计,matlab的api函数不少于420个 ...
最新文章
- 【PAT (Basic Level) 】1015 德才论 (25 分)
- PICRUSt2分析实战:16S扩增子OTU或ASV预测宏基因组EC、通路、KO(200806更新)
- mac下软件包管理brew
- FPGA篇(六)关于Modelsim仿真时不能编译`include文件解决办法【Verilog】【Modelsim】(转)
- 时频分析:短时傅里叶实现(3)
- 面向对象1(super、this)
- 学习,编译ffmpeg tutorial
- 利用Asp.Net Core的MiddleWare思想处理复杂业务流程
- 了解Spring Web初始化
- Quick BI的可视分析之路
- c语言中规定的标准文件,标准C语言
- OpenCV : 仿射变换
- 一加手机刷入第三方Rec
- 如何做决策?SWOT分析
- K均值(K-Means)聚类算法简介
- HNOI 2015 落忆枫音 题解
- Bomb Game(翻译)
- rows between unbounded preceding and current row等,unbounded ,preceding ,following,current row含义详解
- 将Unity地形以Wavefront Obj格式导出
- Request库的相关用法
热门文章
- 2020高处安装、维护、拆除考试试题及高处安装、维护、拆除模拟考试题库
- stm32f3新建工程_青风带你探索stm32f3 系列教程及源代码
- can 转usb【can-usb】【usb can转换】
- 音频处理基础入门笔记
- 对数据库系统的全面、精确、自动化的监控
- C语言中 定义数组大小时 不能使用变量,编程达人 C语言中数组长度不能用变量定义吗...
- jar命令查看查找搜索 jar, war 文件内容
- 外贸Soho创业之前期要做哪些准备,要不要全职开始创业
- 程序员的一天日常(你们也这样的么?)
- VRTRIX数据手套介绍及型号对比