How can I generate a random vector between 1-9 with 10 numbers and at least one number should be >2.
Ältere Kommentare anzeigen
X=rand(10,1)*(9-1)+1 How should I change this code to make at least one number >2.
Akzeptierte Antwort
Weitere Antworten (2)
One way,
X=rand(10,1)*(8-1)+1 +ceil(rand(10,1))
Azzi Abdelmalek
am 21 Dez. 2014
X=rand(10,1)*8+1;
idx=X>2;
if nnz(idx)==0
X(randi(numel(X)))=7*rand+2;
end
1 Kommentar
Hüseyin
am 21 Dez. 2014
Kategorien
Mehr zu Random Number Generation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!