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 Kommentare

gonzalo Mier
gonzalo Mier am 13 Jun. 2019
It seems like a homework. What did you try?
Jan
Jan am 14 Jun. 2019
randi is a little bit easier.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Adam Danz
Adam Danz am 14 Jun. 2019
Bearbeitet: Adam Danz am 17 Jun. 2019

1 Stimme

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

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by