random number between 0 and 1
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
minh lan
am 28 Jun. 2019
Beantwortet: vidhathri bhat
am 28 Jun. 2019
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?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
vidhathri bhat
am 28 Jun. 2019
Hi
Instead of generating the array using randi function, you can create a zeroes array and pick 312 random indices and make them as one. Easy way to get what you want. Hope this helps.
x = zeros(412,1);
ind = randperm(412,312); %generates 312 unique numbers in the range 1 to 412
x(ind)=1;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!