randomly displaying a string from an array

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 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2013 年 6 月 20 日

コメント済み:

2022 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by