matlab randi
时间: 2023-10-01 19:12:17 浏览: 105
randi is a function in MATLAB that generates random integers based on various parameters specified by the user.
Syntax:
randi(imax) generates a random integer between 1 and imax.
randi([imin imax]) generates a random integer between imin and imax.
randi(imax, sz) generates a sz-by-sz matrix of random integers between 1 and imax.
randi([imin imax], sz) generates a sz-by-sz matrix of random integers between imin and imax.
randi(imax, sz1, sz2, ...) generates an array of sz1-by-sz2-by-... random integers between 1 and imax.
randi([imin imax], sz1, sz2, ...) generates an array of sz1-by-sz2-by-... random integers between imin and imax.
Example:
To generate a random integer between 1 and 10:
randi(10)
To generate a 3-by-3 matrix of random integers between 1 and 5:
randi(5, 3)
To generate a 2-by-2-by-2 array of random integers between 10 and 20:
randi([10 20], 2, 2, 2)
阅读全文