randone1

版本 1.0.0.0 (1.0 KB) 作者: Jos (10584)
random array with one 1 per row (and column)
25.0 次下载
更新时间 2016/6/17

查看许可证

randone1 - produces a random array with one 1 per row and column
randone1(N) returns a N-by-N square array with zeros and N ones,
randomly distributed so that each row and each column contains a one 1.

randone1(N,M) where M > N returns a N-by-M array with zeros and N ones,
again with one 1 per row, randomly distributed over the M columns.

Examples
randone1(4,5)
% could yield [0 1 0 0 0 ; 0 0 0 1 0 ; 0 0 0 0 1 ; 0 0 1 0 0]

See also rand, randperm, sort,
nones, randswap (File Exchange)

引用格式

Jos (10584) (2024). randone1 (https://www.mathworks.com/matlabcentral/fileexchange/57725-randone1), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2016a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Creating and Concatenating Matrices 的更多信息
致谢

参考作品: shake, NTRUE, RANDSWAP

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0