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일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2019년 6월 13일

댓글:

2020년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by