开发者

How can I generate a variably-sized matrix of random values in MATLAB?

开发者 https://www.devze.com 2023-02-15 05:44 出处:网络
How can I generate a random matrix with 开发者_开发技巧more rows than columns? For example, with the number of rows being a multiple of the number of columns, like 10 columns 500 rows, or 20 columns 1

How can I generate a random matrix with 开发者_开发技巧more rows than columns? For example, with the number of rows being a multiple of the number of columns, like 10 columns 500 rows, or 20 columns 1000 rows, etc...


You can do these sorts of things using functions like RAND and RANDI. For example:

nCols = randi([10 20]);   %# A random integer between 10 and 20
nRows = nCols*50;         %# Number of rows is a multiple of number of columns
mat = rand(nRows,nCols);  %# A matrix of random values between 0 and 1
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号