Random Generator with known characters

10 次查看(过去 30 天)
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!

采纳的回答

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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by