The function randisum() can draw random integers from a specified distribution, subject to user-specified sum and boundary constraints. Supported distributions are 'uniform', 'skew', 'exponential', and 'gaussian'.
Consider the simplistic example:
% Subdivide a vector into 10 randomly-sized blocks
x = 1:100;
blocksizes = randisum(5,numel(x),[1 10]);
xc = mat2cell(x,1,blocksizes);
I make no claims that these are particularly efficient, robust, or statistically meaningful ways to solve this problem.
Webdocs for randisum():
These tools are part of the MIMT:
引用格式
DGM (2025). Random Integers With a Specified Sum and Range (https://ww2.mathworks.cn/matlabcentral/fileexchange/106185-random-integers-with-a-specified-sum-and-range), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2019b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!randisumpkg
| 版本 | 已发布 | 发行说明 | |
|---|---|---|---|
| 1.0.0 |
