Is there any way in Matlab to generate a 5000 x 1000 matrix of random numbers in which:
MM = betarnd(A,B,1,1000);
but A and B are vectors (1 x 5000). I get the following error message:
??? Error using ==> betarnd at 29
Size information is inconsistent.
I want to avoid a loop like the following one:
for ii = 1 : 1000
MM(:,ii) = betarnd(A,B);
end
Thanks!
You can repeat A
and B
(vectors of size 1x5000) to obtain matrices of size 1000x5000 in which all rows are equal, and use those matrices as inputs to betarnd
. That way you get a result of size 1000x5000 in which column k
contains 1000 random values with parameters A(k)
and B(k)
.
The reason is that, according to the documentation (emphasis mine):
R = betarnd(A,B)
returns an array of random numbers chosen from the beta distribution with parametersA
andB
. The size ofR
is the common size ofA
andB
if both are arrays.
So, use
MM = betarnd(repmat(A(:).',1000,1), repmat(B(:).',1000,1));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments