フィルターのクリア

how to generate a random vector sized 1x100 or 100x1 without the numbers (mod,5)=0 ?

2 ビュー (過去 30 日間)
Hüseyin
Hüseyin 2014 年 12 月 21 日
コメント済み: John D'Errico 2014 年 12 月 22 日
vector sized 1x100 or 100x1 without the numbers (mod,5)=0

回答 (2 件)

Roger Stafford
Roger Stafford 2014 年 12 月 22 日
If you want to range uniformly over the first N positive integers that are not divisible by 5 and you want n random samples, do this:
x = floor(5/4*randi([0,N-1],n,1)+1);

Star Strider
Star Strider 2014 年 12 月 21 日
I have no idea what you actually want or what range the numbers have to be. The simplest way to do what you want is:
rv = [randi([1 4],1,50) randi([6 9],1,50)];
  4 件のコメント
Mustafa
Mustafa 2014 年 12 月 22 日
i do not think so, numbers between 0 and 1 can be divisible by 5.. for example 0.263215/5=.055256643 ??
John D'Errico
John D'Errico 2014 年 12 月 22 日
Mustafa - No. The requirement was that mod(x,5) == 0. A floating point number as you show will not have that property.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by