Random Generator with known characters

9 visualizaciones (últimos 30 días)
Tessa Aus
Tessa Aus el 13 de Jun. de 2019
Comentada: Arjun P Kumar el 25 de Sept. de 2020
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 comentarios
gonzalo Mier
gonzalo Mier el 13 de Jun. de 2019
It seems like a homework. What did you try?
Jan
Jan el 14 de Jun. de 2019
randi is a little bit easier.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 14 de Jun. de 2019
Editada: Adam Danz el 17 de Jun. de 2019
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));

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by