Random Generator with known characters

7 ビュー (過去 30 日間)
Tessa Aus
Tessa Aus 2019 年 6 月 13 日
コメント済み: Arjun P Kumar 2020 年 9 月 25 日
I have a list of known character names Cat, Dog, Goose...etc. These names need to be randomly set into a matrix size 20 x 1
Would look like :
[Cat, Dog, Dog, Goose,Cat,..]
How would one go about using rand to create a matrix such as this.
Thank you!
  2 件のコメント
gonzalo Mier
gonzalo Mier 2019 年 6 月 13 日
It seems like a homework. What did you try?
Jan
Jan 2019 年 6 月 14 日
randi is a little bit easier.

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

採用された回答

Adam Danz
Adam Danz 2019 年 6 月 14 日
編集済み: Adam Danz 2019 年 6 月 17 日
Use randperm() or randi() One of those resamples without replacement while the other resamples with replacement (I'll let you read through the documentation to decide which is best).
c = {'cat','dog','goose','rhesis macaque','mongoose'};
cr = c(randperm(numel(c)));
% or
cr = c(randi(numel(c),1,20));
  1 件のコメント
Arjun P Kumar
Arjun P Kumar 2020 年 9 月 25 日
Thank you so much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by