Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

matrix

matlab

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...

like image 253
edgarmtze Avatar asked Mar 08 '11 05:03

edgarmtze


People also ask

How do you create a random size matrix in Matlab?

You can use the randperm function to create a double array of random integer values that have no repeated values. For example, r4 = randperm(15,5);

How do you generate a random Nxn matrix in Matlab?

rand (MATLAB Functions) The rand function generates arrays of random numbers whose elements are uniformly distributed in the interval ( 0 , 1 ). Y = rand(n) returns an n -by- n matrix of random entries. An error message appears if n is not a scalar.

How do you create a random integer matrix?

To create a matrix of random integers in Python, randint() function of the numpy module is used. This function is used for random sampling i.e. all the numbers generated will be at random and cannot be predicted at hand. Parameters : low : [int] Lowest (signed) integer to be drawn from the distribution.


1 Answers

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
like image 67
gnovice Avatar answered Nov 13 '22 10:11

gnovice