MATLAB: Random number between 0 and 1

rand

I want to create random vector between 0 and 1 for 412 elements, by using
logical(randi([0 1],[412,1]));
It's work. But now, I want to have the number of '0' is 100, the number of '1' is 312. How I can do?

Best Answer

>> V = [zeros(1,100),ones(1,312)];
>> V = V(randperm(numel(V)));
Checking:
>> nnz(V==0)
ans = 100
>> nnz(V==1)
ans = 312
>> V(:)
ans =
1
0
1
1
1
1
1
... lots of rows here
1
1
1
1
1
0
1
0
1
1
1