randomly displaying a string from an array

6 次查看(过去 30 天)
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)));

更多回答(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