How can I effectively create large random vectors without resorting to loops?

Problem: - I want to create 50 instances of a vector (1 Size) that contains random real numbers (float). The size of the array (1 size) will affect 30 thousand. How can I continue so that the overhead is minimal or minimal complexity?

+5
source share
2 answers
N = 30000; %// length of your vectors
I = 50; %// number of instances
v = rand(I, N); 

In the above example, you will create a matrix in which each row will be a single vector. Random numbers are generated with a uniform distribution (use for Gaussian distribution randn).

If you need to create each instance separately, use a loop:

for i=1:I
    v = rand(1, N);
    %// do something with v
end

, ( ).

:
:
, . Matlab .
, 50 :

 x1 = sigma*y + beta * vect1;
 ...
 x50 = sigma*y + beta * vect50;

, y - 1x30000, :

X = sigma*repmat(y, 50, 1) + beta * rand(50, 30000);

: - , :

X(1,:) = x1;
...
X(50,:) = x50;

repmat(y,50,1) y 50 ()

+4

50x30k

values = rand(50, 30000)

30k

 aVector = values(3,:)  % Row 3, all columns
+4

All Articles