Random Generator with known characters

조회 수: 16 (최근 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));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by