creating a variable to use for grouping data

2 ビュー (過去 30 日間)
Rabeya
Rabeya 2012 年 4 月 20 日
I want to create a variable (a column vector) with a specific length (8000), containing values 1 to 10 randomly assigned and with a specific average repetition of each number (say 800). How to do this?

採用された回答

Walter Roberson
Walter Roberson 2012 年 4 月 20 日
If the number of repetitions is to be exact:
t = repmat(1:10.', 800, 1);
t(randperm(length(t)))
If the repetitions need not be exact:
1 + floor(10 * rand(8000,1))
  2 件のコメント
Rabeya
Rabeya 2012 年 4 月 20 日
Very impressive!
Walter Roberson
Walter Roberson 2012 年 4 月 20 日
Opps, I had an extra layer of repmat() on the first solution! I have edited.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by