Borrar filtros
Borrar filtros

randomly displaying a string from an array

13 visualizaciones (últimos 30 días)
kenny
kenny el 20 de Jun. de 2013
Comentada: Souarv De el 22 de Mzo. de 2022
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))

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 20 de Jun. de 2013
out = X(randi(numel(X)));
  2 comentarios
Muthu Annamalai
Muthu Annamalai el 20 de Jun. de 2013
be sure to use the new rng() function, and seed it in a non-predictable way.
Souarv De
Souarv De el 22 de Mzo. de 2022
What to do if I want non-repeatative sequence?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by