필터 지우기
필터 지우기

randomly displaying a string from an array

조회 수: 13 (최근 30일)
kenny
kenny 2013년 6월 20일
댓글: Souarv De 2022년 3월 22일
hi! I was hoping to randomly display one of the following four greetings each iteration, but when i run it, it says that I can't use "any". and when i try "rand" a similar problem occurs where the input must be numeric- how would i do this with strings?
thank you
??? Undefined function or method 'any' for input arguments of type 'cell'.
code:
X = {'hello buddy', 'hi there', 'good morning', 'top o' the morning'}
disp(any(X))

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 6월 20일
out = X(randi(numel(X)));
  댓글 수: 2
Muthu Annamalai
Muthu Annamalai 2013년 6월 20일
be sure to use the new rng() function, and seed it in a non-predictable way.
Souarv De
Souarv De 2022년 3월 22일
What to do if I want non-repeatative sequence?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by